test262/test/intl402/12.3.2_FDT_7_a_iv.js

35 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright 2012 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es5id: 12.3.2_FDT_7_a_iv
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 + ".");
}
});