From bb4fda3b97e6888347430c5444a0309f17515ade Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 1 Feb 2023 21:03:59 +0000 Subject: [PATCH] LibJS: Format the era of ISO year 0 as BC This is a normative change in the ECMA-402 spec. See: https://github.com/tc39/ecma402/commit/2034315 --- .../Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp | 4 ++-- .../DateTimeFormat/DateTimeFormat.prototype.format.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp index f5cc19ef72..9dc9247026 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp @@ -1235,8 +1235,8 @@ ThrowCompletionOr to_local_time(VM& vm, Crypto::SignedBigInteger cons return LocalTime { // WeekDay(𝔽(floor(tz / 10^6))) .weekday = week_day(zoned_time), - // Let year be YearFromTime(𝔽(floor(tz / 10^6))). If year < -0𝔽, return "BC", else return "AD". - .era = year < 0 ? ::Locale::Era::BC : ::Locale::Era::AD, + // Let year be YearFromTime(𝔽(floor(tz / 10^6))). If year < 1𝔽, return "BC", else return "AD". + .era = year < 1 ? ::Locale::Era::BC : ::Locale::Era::AD, // YearFromTime(𝔽(floor(tz / 10^6))) .year = year, // undefined. diff --git a/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.format.js b/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.format.js index 2661208e22..a8a04a681b 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.format.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.format.js @@ -161,6 +161,17 @@ describe("era", () => { expect(ar.format(d1)).toBe(d.ar1); }); }); + + test("Year 1 BC (ISO year 0)", () => { + let year1BC = new Date(Date.UTC(0)); + year1BC.setUTCFullYear(0); + + const en = new Intl.DateTimeFormat("en", { era: "short", timeZone: "UTC" }); + expect(en.format(year1BC)).toBe("1/1/1 BC"); + + const ar = new Intl.DateTimeFormat("ar", { era: "short", timeZone: "UTC" }); + expect(ar.format(year1BC)).toBe("١ ١ ١ ق.م"); + }); }); describe("year", () => {