michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 398485; michael@0: var summary = 'Date.prototype.toLocaleString should not clamp year'; michael@0: var actual = ''; michael@0: var expect = ''; michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: var d; michael@0: var y; michael@0: var l; michael@0: var maxms = 8640000000000000; michael@0: michael@0: d = new Date(-maxms ); michael@0: y = d.getFullYear(); michael@0: michael@0: actual = y; michael@0: expect = -271821; michael@0: reportCompare(expect, actual, summary + ': check year'); michael@0: michael@0: l = d.toLocaleString(); michael@0: print(l); michael@0: if (this.hasOwnProperty("Intl")) { michael@0: // ECMA-402 specifies that toLocaleString uses a proleptic Gregorian michael@0: // calender without year 0. michael@0: // Also, localized strings usually use era indicators such as "BC" michael@0: // instead of minus signs. michael@0: expect = Math.abs(y - 1) + ''; michael@0: } else { michael@0: // ECMA-262 up to edition 5.1 didn't specify toLocaleString; michael@0: // the previous implementation assumed a calendar with year 0 and used michael@0: // minus sign. michael@0: expect = y + ''; michael@0: } michael@0: actual = l.match(/-?[0-9]{3,}/) + ''; michael@0: reportCompare(expect, actual, summary + ': check toLocaleString'); michael@0: michael@0: d = new Date(maxms ); michael@0: y = d.getFullYear(); michael@0: l = d.toLocaleString(); michael@0: print(l); michael@0: michael@0: actual = y; michael@0: expect = 275760; michael@0: reportCompare(expect, actual, summary + ': check year'); michael@0: michael@0: actual = l.match(new RegExp(y)) + ''; michael@0: expect = y + ''; michael@0: reportCompare(expect, actual, summary + ': check toLocaleString'); michael@0: michael@0: exitFunc ('test'); michael@0: }