From 788bc809bf8a6adf9d71ecd2010ccfcbb7b67249 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Wed, 1 Feb 2023 11:50:39 -0500 Subject: [PATCH] Update DateTimeFormat proleptic Gregorian testing to include era (#3722) Ref https://github.com/tc39/ecma402/issues/723 --- .../prototype/format/proleptic-gregorian-calendar.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/intl402/DateTimeFormat/prototype/format/proleptic-gregorian-calendar.js b/test/intl402/DateTimeFormat/prototype/format/proleptic-gregorian-calendar.js index 749fc55ee2..24e67d369c 100644 --- a/test/intl402/DateTimeFormat/prototype/format/proleptic-gregorian-calendar.js +++ b/test/intl402/DateTimeFormat/prototype/format/proleptic-gregorian-calendar.js @@ -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 + "."); });