diff options
Diffstat (limited to 'test/suite/intl402/ch12/12.3/12.3.2_FDT_7_a_iv.js')
-rw-r--r-- | test/suite/intl402/ch12/12.3/12.3.2_FDT_7_a_iv.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/suite/intl402/ch12/12.3/12.3.2_FDT_7_a_iv.js b/test/suite/intl402/ch12/12.3/12.3.2_FDT_7_a_iv.js new file mode 100644 index 000000000..f13878403 --- /dev/null +++ b/test/suite/intl402/ch12/12.3/12.3.2_FDT_7_a_iv.js @@ -0,0 +1,32 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that format uses a proleptic Gregorian calendar with no year 0. + * @author Norbert Lindenberg + */ + +var dates = [ + 0, // January 1, 1970 + -62151602400000, // in June 1 BC + -8640000000000000 // beginning of ECMAScript time +]; + +var format = new Intl.DateTimeFormat(["en-US"], {year: "numeric", month: "long", timeZone: "UTC"}); + +// this test requires a Gregorian calendar, which we usually find in the US +if (format.resolvedOptions().calendar !== "gregory") { + $ERROR("Internal error: Didn't find Gregorian calendar"); +} + +dates.forEach(function (date) { + var year = new Date(date).getUTCFullYear(); + var expectedYear = year <= 0 ? 1 - year : year; + var expectedYearString = expectedYear.toLocaleString(["en-US"], {useGrouping: false}); + var dateString = format.format(date); + if (dateString.indexOf(expectedYearString) === -1) { + $ERROR("Formatted year doesn't contain expected year – expected " + + expectedYearString + ", got " + dateString + "."); + } +}); + |