From bf79c731583d3d887b23fb9d9ef5fde9af35a9e1 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 30 Nov 2021 21:23:13 -0500 Subject: [PATCH] LibUnicode: Do not generate data for "generic" calendars This is not a calendar supported by ECMA-402, so let's not waste space with its data. Further, don't generate "gregorian" as a valid Unicode locale extension keyword. It's an invalid type identifier, thus cannot be used in locales such as "en-u-ca-gregorian". --- .../GenerateUnicodeDateTimeFormat.cpp | 5 +++++ .../LibUnicode/GenerateUnicodeLocale.cpp | 7 ++++++- ...ateTimeFormat.prototype.resolvedOptions.js | 19 +++++++------------ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp index 89ed7090920..607993d790c 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp @@ -151,6 +151,11 @@ static ErrorOr parse_calendars(String locale_calendars_path, UnicodeLocale }; calendars_object.as_object().for_each_member([&](auto const& calendar_name, JsonValue const& value) { + // The generic calendar is not a supported Unicode calendar key, so skip it: + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar#unicode_calendar_keys + if (calendar_name == "generic"sv) + return; + auto& calendar = ensure_calendar(calendar_name); if (!locale_data.calendars.contains_slow(calendar_name)) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp index c669cdf7c64..3f0e2d018ae 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeLocale.cpp @@ -407,12 +407,17 @@ static ErrorOr parse_calendar_keywords(String locale_dates_path, UnicodeLo auto const& calendars_object = dates_object.as_object().get("calendars"sv); calendars_object.as_object().for_each_member([&](auto const& calendar_name, JsonValue const&) { - keyword_values.append(calendar_name); + // The generic calendar is not a supported Unicode calendar key, so skip it: + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar#unicode_calendar_keys + if (calendar_name == "generic"sv) + return; // FIXME: Similar to the calendar aliases defined in GenerateUnicodeDateTimeFormat, this // should be parsed from BCP47. https://unicode-org.atlassian.net/browse/CLDR-15158 if (calendar_name == "gregorian"sv) keyword_values.append("gregory"sv); + else + keyword_values.append(calendar_name); }); } diff --git a/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.resolvedOptions.js b/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.resolvedOptions.js index 466311a6151..f8a903c227c 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.resolvedOptions.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.resolvedOptions.js @@ -21,32 +21,27 @@ describe("correct behavior", () => { const en = Intl.DateTimeFormat("en", { calendar: "gregory" }); expect(en.resolvedOptions().calendar).toBe("gregory"); - const el = Intl.DateTimeFormat("el", { calendar: "generic" }); - expect(el.resolvedOptions().calendar).toBe("generic"); + const el = Intl.DateTimeFormat("el", { calendar: "gregory" }); + expect(el.resolvedOptions().calendar).toBe("gregory"); }); test("calendar may be set by locale extension", () => { const en = Intl.DateTimeFormat("en-u-ca-gregory"); expect(en.resolvedOptions().calendar).toBe("gregory"); - const el = Intl.DateTimeFormat("el-u-ca-generic"); - expect(el.resolvedOptions().calendar).toBe("generic"); + const el = Intl.DateTimeFormat("el-u-ca-gregory"); + expect(el.resolvedOptions().calendar).toBe("gregory"); }); test("calendar option overrides locale extension", () => { - const el = Intl.DateTimeFormat("el-u-ca-generic", { calendar: "gregory" }); + const el = Intl.DateTimeFormat("el-u-ca-gregory", { calendar: "gregory" }); expect(el.resolvedOptions().calendar).toBe("gregory"); }); test("calendar option limited to known 'ca' values", () => { - ["generic", "hello"].forEach(calendar => { + ["gregory", "hello"].forEach(calendar => { const en = Intl.DateTimeFormat("en", { calendar: calendar }); - expect(en.resolvedOptions().calendar).toBe("generic"); - }); - - ["generic", "hello"].forEach(calendar => { - const en = Intl.DateTimeFormat(`en-u-ca-${calendar}`); - expect(en.resolvedOptions().calendar).toBe("generic"); + expect(en.resolvedOptions().calendar).toBe("gregory"); }); });