summaryrefslogtreecommitdiff
path: root/test/suite/intl402/ch12/12.3/12.3.2_FDT_7_a_iv.js
blob: f13878403954d70883ab8085bd89ff3c04a84777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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 + ".");
    }
});