diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-07-07 13:59:46 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-08 11:51:54 +0200 |
commit | bf85bf2a9ec076a9bfa0ff0cfb2a97b2059818fc (patch) | |
tree | 1b62a97015cb19124d6f7ba505257b2622050fe0 /Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp | |
parent | 36abcd820d1a5b899f67469d418985863d68232a (diff) | |
download | serenity-bf85bf2a9ec076a9bfa0ff0cfb2a97b2059818fc.zip |
LibJS: Use Intl.PluralRules within Intl.RelativeFormat
The Polish test cases added here cover previous failures from test262,
due to the way that 0 is specified to be "many" in Polish.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp index 1bbf45be2a..c80252d981 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/RelativeTimeFormat.cpp @@ -10,8 +10,8 @@ #include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/Intl/NumberFormat.h> #include <LibJS/Runtime/Intl/NumberFormatConstructor.h> +#include <LibJS/Runtime/Intl/PluralRules.h> #include <LibJS/Runtime/Intl/RelativeTimeFormat.h> -#include <LibUnicode/NumberFormat.h> namespace JS::Intl { @@ -26,6 +26,8 @@ void RelativeTimeFormat::visit_edges(Cell::Visitor& visitor) Base::visit_edges(visitor); if (m_number_format) visitor.visit(m_number_format); + if (m_plural_rules) + visitor.visit(m_plural_rules); } void RelativeTimeFormat::set_numeric(StringView numeric) @@ -179,10 +181,11 @@ ThrowCompletionOr<Vector<PatternPartitionWithUnit>> partition_relative_time_patt auto value_partitions = partition_number_pattern(global_object, relative_time_format.number_format(), Value(value)); // 21. Let pr be ! ResolvePlural(relativeTimeFormat.[[PluralRules]], value). + auto plurality = resolve_plural(global_object, relative_time_format.plural_rules(), Value(value)); + // 22. Let pattern be po.[[<pr>]]. - // FIXME: Use ResolvePlural when Intl.PluralRules is implemented. - auto pattern = Unicode::select_pattern_with_plurality(patterns, value); - if (!pattern.has_value()) + auto pattern = patterns.find_if([&](auto& p) { return p.plurality == plurality; }); + if (pattern == patterns.end()) return Vector<PatternPartitionWithUnit> {}; // 23. Return ! MakePartsList(pattern, unit, fv). |