Update DateTimeFormat proleptic Gregorian testing to include era (#3722)

Ref https://github.com/tc39/ecma402/issues/723
This commit is contained in:
Richard Gibson 2023-02-01 11:50:39 -05:00 committed by GitHub
parent a157570ddc
commit 788bc809bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -15,7 +15,7 @@ var dates = [
-8640000000000000 // beginning of ECMAScript time
];
var format = new Intl.DateTimeFormat(["en-US"], {year: "numeric", month: "long", timeZone: "UTC"});
var format = new Intl.DateTimeFormat(["en-US"], {year: "numeric", era: "short", timeZone: "UTC"});
// this test requires a Gregorian calendar, which we usually find in the US
assert.sameValue(format.resolvedOptions().calendar, "gregory", "Internal error: Didn't find Gregorian calendar");
@ -24,6 +24,8 @@ 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 expectedEra = year <= 0 ? /BC/ : /AD|(?:^|[^B])CE/;
var dateString = format.format(date);
assert.notSameValue(dateString.indexOf(expectedYearString), -1, "Formatted year doesn't contain expected year expected " + expectedYearString + ", got " + dateString + ".");
assert(expectedEra.test(dateString), "Formatted year doesn't contain expected era expected " + expectedEra + ", got " + dateString + ".");
});