diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-12-06 22:50:54 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-12-08 11:29:36 +0000 |
commit | 9f7c7277201df5649a6b229d73e2273835b873ff (patch) | |
tree | b343bd7f64ac9a8201976ecbb2d5100906046a58 /Meta/Lagom | |
parent | 6ace4000bf9127c43fe1ce4c5c49015e0467deaa (diff) | |
download | serenity-9f7c7277201df5649a6b229d73e2273835b873ff.zip |
LibJS+LibUnicode: Generate missing patterns with fractionalSecondDigits
TR-35's Matching Skeleton algorithm dictates how user requests including
fractional second digits should be handled when the CLDR format pattern
does not include that field. When the format pattern contains {second},
but does not contain {fractionalSecondDigits}, generate a second pattern
which appends "{decimal}{fractionalSecondDigits}" to the {second} field.
Diffstat (limited to 'Meta/Lagom')
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeDateTimeFormat.cpp index b54772dbf8..45db9b22fa 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<CalendarPattern return locale_data.unique_strings.ensure(move(new_pattern)); }; + auto inject_fractional_second_digits = [&](auto format) { + auto pattern = locale_data.unique_strings.get(format); + + auto new_pattern = pattern.replace("{second}"sv, "{second}{decimal}{fractionalSecondDigits}"sv); + return locale_data.unique_strings.ensure(move(new_pattern)); + }; + auto append_if_unique = [&](auto format) { auto format_index = locale_data.unique_patterns.ensure(move(format)); @@ -473,11 +480,28 @@ static void generate_missing_patterns(Calendar& calendar, Vector<CalendarPattern calendar.available_formats.append(format_index); }; + Vector<CalendarPattern> 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; |