diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp index b54772dbf84..45db9b22fae 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp @@ -466,6 +466,13 @@ static void generate_missing_patterns(Calendar& calendar, Vector time_formats_with_fractional_second_digits; + for (auto const& format : date_formats) append_if_unique(format); - for (auto const& format : time_formats) + for (auto const& format : time_formats) { append_if_unique(format); + if (format.second.has_value() && !format.fractional_second_digits.has_value()) { + auto new_format = format; + new_format.fractional_second_digits = 2; + + new_format.pattern_index = inject_fractional_second_digits(new_format.pattern_index); + if (new_format.pattern12_index != 0) + new_format.pattern12_index = inject_fractional_second_digits(new_format.pattern12_index); + + time_formats_with_fractional_second_digits.append(new_format); + append_if_unique(move(new_format)); + } + } + + time_formats.extend(move(time_formats_with_fractional_second_digits)); + for (auto const& date_format : date_formats) { CalendarPatternIndexType date_time_format_index = 0; diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp index 9f7ad9c14fb..7660ace7062 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp @@ -659,9 +659,18 @@ Optional basic_format_matcher(Unicode::CalendarPattern // // Rather than generating an prohibitively large amount of nearly-duplicate patterns, which only // differ by field length, we expand the field lengths here. - best_format->for_each_calendar_field_zipped_with(options, [](auto& best_format_field, auto const& option_field, auto) { - if (best_format_field.has_value() && option_field.has_value()) - best_format_field = option_field; + best_format->for_each_calendar_field_zipped_with(options, [&](auto& best_format_field, auto const& option_field, auto field_type) { + switch (field_type) { + case Unicode::CalendarPattern::Field::FractionalSecondDigits: + if (best_format->second.has_value() && option_field.has_value()) + best_format_field = option_field; + break; + + default: + if (best_format_field.has_value() && option_field.has_value()) + best_format_field = option_field; + break; + } }); // 11. Return bestFormat. 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 cb9ff39372c..da70832e149 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 @@ -1,6 +1,3 @@ -// NOTE: We cannot yet test the fractionalSecondDigits option. There aren't any patterns in the CLDR -// with this field ('S' in https://unicode.org/reports/tr35/tr35-dates.html#dfst-second). We -// will need to figure out how this field should be generated. describe("correct behavior", () => { test("length is 0", () => { expect(Intl.DateTimeFormat.prototype.resolvedOptions).toHaveLength(0); @@ -179,6 +176,15 @@ describe("correct behavior", () => { }); }); + test("fractionalSecondDigits", () => { + [1, 2, 3].forEach(fractionalSecondDigits => { + const en = new Intl.DateTimeFormat("en", { + fractionalSecondDigits: fractionalSecondDigits, + }); + expect(en.resolvedOptions().fractionalSecondDigits).toBe(fractionalSecondDigits); + }); + }); + test("timeZoneName", () => { ["short", "long"].forEach(timeZoneName => { const en = new Intl.DateTimeFormat("en", { timeZoneName: timeZoneName });