mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 20:27:35 +00:00
LibJS: Implement Intl.RelativeTimeFormat.prototype.format
This commit is contained in:
parent
8098eb273a
commit
9c5d7e515c
6 changed files with 662 additions and 1 deletions
|
@ -39,8 +39,10 @@
|
||||||
M(IntlInvalidDateTimeFormatOption, "Option {} cannot be set when also providing {}") \
|
M(IntlInvalidDateTimeFormatOption, "Option {} cannot be set when also providing {}") \
|
||||||
M(IntlInvalidLanguageTag, "{} is not a structurally valid language tag") \
|
M(IntlInvalidLanguageTag, "{} is not a structurally valid language tag") \
|
||||||
M(IntlInvalidTime, "Time value must be between -8.64E15 and 8.64E15") \
|
M(IntlInvalidTime, "Time value must be between -8.64E15 and 8.64E15") \
|
||||||
|
M(IntlInvalidUnit, "Unit {} is not a valid time unit") \
|
||||||
M(IntlStartTimeAfterEndTime, "Start time {} is after end time {}") \
|
M(IntlStartTimeAfterEndTime, "Start time {} is after end time {}") \
|
||||||
M(IntlMinimumExceedsMaximum, "Minimum value {} is larger than maximum value {}") \
|
M(IntlMinimumExceedsMaximum, "Minimum value {} is larger than maximum value {}") \
|
||||||
|
M(IntlNumberIsNaNOrInfinity, "Number must not be NaN or Infinity") \
|
||||||
M(IntlNumberIsNaNOrOutOfRange, "Value {} is NaN or is not between {} and {}") \
|
M(IntlNumberIsNaNOrOutOfRange, "Value {} is NaN or is not between {} and {}") \
|
||||||
M(IntlOptionUndefined, "Option {} must be defined when option {} is {}") \
|
M(IntlOptionUndefined, "Option {} must be defined when option {} is {}") \
|
||||||
M(InvalidAssignToConst, "Invalid assignment to const variable") \
|
M(InvalidAssignToConst, "Invalid assignment to const variable") \
|
||||||
|
|
|
@ -4,12 +4,13 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibJS/Runtime/AbstractOperations.h>
|
#include <LibJS/Runtime/AbstractOperations.h>
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
#include <LibJS/Runtime/Intl/AbstractOperations.h>
|
|
||||||
#include <LibJS/Runtime/Intl/NumberFormat.h>
|
#include <LibJS/Runtime/Intl/NumberFormat.h>
|
||||||
#include <LibJS/Runtime/Intl/NumberFormatConstructor.h>
|
#include <LibJS/Runtime/Intl/NumberFormatConstructor.h>
|
||||||
#include <LibJS/Runtime/Intl/RelativeTimeFormat.h>
|
#include <LibJS/Runtime/Intl/RelativeTimeFormat.h>
|
||||||
|
#include <LibUnicode/NumberFormat.h>
|
||||||
|
|
||||||
namespace JS::Intl {
|
namespace JS::Intl {
|
||||||
|
|
||||||
|
@ -122,4 +123,194 @@ ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(GlobalObj
|
||||||
return &relative_time_format;
|
return &relative_time_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 17.1.2 SingularRelativeTimeUnit ( unit ), https://tc39.es/ecma402/#sec-singularrelativetimeunit
|
||||||
|
ThrowCompletionOr<Unicode::TimeUnit> singular_relative_time_unit(GlobalObject& global_object, StringView unit)
|
||||||
|
{
|
||||||
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
|
// 1. Assert: Type(unit) is String.
|
||||||
|
|
||||||
|
// 2. If unit is "seconds", return "second".
|
||||||
|
if (unit == "seconds"sv)
|
||||||
|
return Unicode::TimeUnit::Second;
|
||||||
|
// 3. If unit is "minutes", return "minute".
|
||||||
|
if (unit == "minutes"sv)
|
||||||
|
return Unicode::TimeUnit::Minute;
|
||||||
|
// 4. If unit is "hours", return "hour".
|
||||||
|
if (unit == "hours"sv)
|
||||||
|
return Unicode::TimeUnit::Hour;
|
||||||
|
// 5. If unit is "days", return "day".
|
||||||
|
if (unit == "days"sv)
|
||||||
|
return Unicode::TimeUnit::Day;
|
||||||
|
// 6. If unit is "weeks", return "week".
|
||||||
|
if (unit == "weeks"sv)
|
||||||
|
return Unicode::TimeUnit::Week;
|
||||||
|
// 7. If unit is "months", return "month".
|
||||||
|
if (unit == "months"sv)
|
||||||
|
return Unicode::TimeUnit::Month;
|
||||||
|
// 8. If unit is "quarters", return "quarter".
|
||||||
|
if (unit == "quarters"sv)
|
||||||
|
return Unicode::TimeUnit::Quarter;
|
||||||
|
// 9. If unit is "years", return "year".
|
||||||
|
if (unit == "years"sv)
|
||||||
|
return Unicode::TimeUnit::Year;
|
||||||
|
|
||||||
|
// 10. If unit is not one of "second", "minute", "hour", "day", "week", "month", "quarter", or "year", throw a RangeError exception.
|
||||||
|
// 11. Return unit.
|
||||||
|
if (auto time_unit = Unicode::time_unit_from_string(unit); time_unit.has_value())
|
||||||
|
return *time_unit;
|
||||||
|
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlInvalidUnit, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 17.1.3 PartitionRelativeTimePattern ( relativeTimeFormat, value, unit ), https://tc39.es/ecma402/#sec-PartitionRelativeTimePattern
|
||||||
|
ThrowCompletionOr<Vector<PatternPartitionWithUnit>> partition_relative_time_pattern(GlobalObject& global_object, RelativeTimeFormat& relative_time_format, double value, StringView unit)
|
||||||
|
{
|
||||||
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
|
// 1. Assert: relativeTimeFormat has an [[InitializedRelativeTimeFormat]] internal slot.
|
||||||
|
// 2. Assert: Type(value) is Number.
|
||||||
|
// 3. Assert: Type(unit) is String.
|
||||||
|
|
||||||
|
// 4. If value is NaN, +∞𝔽, or -∞𝔽, throw a RangeError exception.
|
||||||
|
if (!Value(value).is_finite_number())
|
||||||
|
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlNumberIsNaNOrInfinity);
|
||||||
|
|
||||||
|
// 5. Let unit be ? SingularRelativeTimeUnit(unit).
|
||||||
|
auto time_unit = TRY(singular_relative_time_unit(global_object, unit));
|
||||||
|
|
||||||
|
// 6. Let localeData be %RelativeTimeFormat%.[[LocaleData]].
|
||||||
|
// 7. Let dataLocale be relativeTimeFormat.[[DataLocale]].
|
||||||
|
auto const& data_locale = relative_time_format.data_locale();
|
||||||
|
|
||||||
|
// 8. Let fields be localeData.[[<dataLocale>]].
|
||||||
|
|
||||||
|
// 9. Let style be relativeTimeFormat.[[Style]].
|
||||||
|
auto style = relative_time_format.style();
|
||||||
|
|
||||||
|
// NOTE: The next steps form a "key" based on combining various formatting options into a string,
|
||||||
|
// then filtering the large set of locale data down to the pattern we are looking for. Instead,
|
||||||
|
// LibUnicode expects the individual options as enumeration values, and returns the couple of
|
||||||
|
// patterns that match those options.
|
||||||
|
auto find_patterns_for_tense_or_number = [&](StringView tense_or_number) {
|
||||||
|
// 10. If style is equal to "short", then
|
||||||
|
// a. Let entry be the string-concatenation of unit and "-short".
|
||||||
|
// 11. Else if style is equal to "narrow", then
|
||||||
|
// a. Let entry be the string-concatenation of unit and "-narrow".
|
||||||
|
// 12. Else,
|
||||||
|
// a. Let entry be unit.
|
||||||
|
auto patterns = Unicode::get_relative_time_format_patterns(data_locale, time_unit, tense_or_number, style);
|
||||||
|
|
||||||
|
// 13. If fields doesn't have a field [[<entry>]], then
|
||||||
|
if (patterns.is_empty()) {
|
||||||
|
// a. Let entry be unit.
|
||||||
|
// NOTE: In the CLDR, the lack of "short" or "narrow" in the key implies "long".
|
||||||
|
patterns = Unicode::get_relative_time_format_patterns(data_locale, time_unit, tense_or_number, Unicode::Style::Long);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 14. Let patterns be fields.[[<entry>]].
|
||||||
|
return patterns;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 15. Let numeric be relativeTimeFormat.[[Numeric]].
|
||||||
|
// 16. If numeric is equal to "auto", then
|
||||||
|
if (relative_time_format.numeric() == RelativeTimeFormat::Numeric::Auto) {
|
||||||
|
// a. Let valueString be ToString(value).
|
||||||
|
auto value_string = MUST(Value(value).to_string(global_object));
|
||||||
|
|
||||||
|
// b. If patterns has a field [[<valueString>]], then
|
||||||
|
if (auto patterns = find_patterns_for_tense_or_number(value_string); !patterns.is_empty()) {
|
||||||
|
VERIFY(patterns.size() == 1);
|
||||||
|
|
||||||
|
// i. Let result be patterns.[[<valueString>]].
|
||||||
|
auto result = patterns[0].pattern.to_string();
|
||||||
|
|
||||||
|
// ii. Return a List containing the Record { [[Type]]: "literal", [[Value]]: result }.
|
||||||
|
return Vector<PatternPartitionWithUnit> { { "literal"sv, move(result) } };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 17. If value is -0𝔽 or if value is less than 0, then
|
||||||
|
StringView tense;
|
||||||
|
if (Value(value).is_negative_zero() || (value < 0)) {
|
||||||
|
// a. Let tl be "past".
|
||||||
|
tense = "past"sv;
|
||||||
|
|
||||||
|
// FIXME: The spec does not say to do this, but nothing makes sense after this with a negative value.
|
||||||
|
value = fabs(value);
|
||||||
|
}
|
||||||
|
// 18. Else,
|
||||||
|
else {
|
||||||
|
// a. Let tl be "future".
|
||||||
|
tense = "future"sv;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 19. Let po be patterns.[[<tl>]].
|
||||||
|
auto patterns = find_patterns_for_tense_or_number(tense);
|
||||||
|
|
||||||
|
// 20. Let fv be ! PartitionNumberPattern(relativeTimeFormat.[[NumberFormat]], value).
|
||||||
|
auto value_partitions = partition_number_pattern(relative_time_format.number_format(), value);
|
||||||
|
|
||||||
|
// 21. Let pr be ! ResolvePlural(relativeTimeFormat.[[PluralRules]], 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())
|
||||||
|
return Vector<PatternPartitionWithUnit> {};
|
||||||
|
|
||||||
|
// 23. Return ! MakePartsList(pattern, unit, fv).
|
||||||
|
return make_parts_list(pattern->pattern, Unicode::time_unit_to_string(time_unit), move(value_partitions));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 17.1.4 MakePartsList ( pattern, unit, parts ), https://tc39.es/ecma402/#sec-makepartslist
|
||||||
|
Vector<PatternPartitionWithUnit> make_parts_list(StringView pattern, StringView unit, Vector<PatternPartition> parts)
|
||||||
|
{
|
||||||
|
// 1. Let patternParts be PartitionPattern(pattern).
|
||||||
|
auto pattern_parts = partition_pattern(pattern);
|
||||||
|
|
||||||
|
// 2. Let result be a new empty List.
|
||||||
|
Vector<PatternPartitionWithUnit> result;
|
||||||
|
|
||||||
|
// 3. For each Record { [[Type]], [[Value]] } patternPart in patternParts, do
|
||||||
|
for (auto& pattern_part : pattern_parts) {
|
||||||
|
// a. If patternPart.[[Type]] is "literal", then
|
||||||
|
if (pattern_part.type == "literal"sv) {
|
||||||
|
// i. Append Record { [[Type]]: "literal", [[Value]]: patternPart.[[Value]], [[Unit]]: empty } to result.
|
||||||
|
result.empend("literal"sv, move(pattern_part.value));
|
||||||
|
}
|
||||||
|
// b. Else,
|
||||||
|
else {
|
||||||
|
// i. Assert: patternPart.[[Type]] is "0".
|
||||||
|
VERIFY(pattern_part.type == "0"sv);
|
||||||
|
|
||||||
|
// ii. For each Record { [[Type]], [[Value]] } part in parts, do
|
||||||
|
for (auto& part : parts) {
|
||||||
|
// 1. Append Record { [[Type]]: part.[[Type]], [[Value]]: part.[[Value]], [[Unit]]: unit } to result.
|
||||||
|
result.empend(part.type, move(part.value), unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Return result.
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 17.1.5 FormatRelativeTime ( relativeTimeFormat, value, unit ), https://tc39.es/ecma402/#sec-FormatRelativeTime
|
||||||
|
ThrowCompletionOr<String> format_relative_time(GlobalObject& global_object, RelativeTimeFormat& relative_time_format, double value, StringView unit)
|
||||||
|
{
|
||||||
|
// 1. Let parts be ? PartitionRelativeTimePattern(relativeTimeFormat, value, unit).
|
||||||
|
auto parts = TRY(partition_relative_time_pattern(global_object, relative_time_format, value, unit));
|
||||||
|
|
||||||
|
// 2. Let result be an empty String.
|
||||||
|
StringBuilder result;
|
||||||
|
|
||||||
|
// 3. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do
|
||||||
|
for (auto& part : parts) {
|
||||||
|
// a. Set result to the string-concatenation of result and part.[[Value]].
|
||||||
|
result.append(move(part.value));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Return result.
|
||||||
|
return result.build();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,10 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <LibJS/Runtime/Completion.h>
|
#include <LibJS/Runtime/Completion.h>
|
||||||
|
#include <LibJS/Runtime/Intl/AbstractOperations.h>
|
||||||
#include <LibJS/Runtime/Object.h>
|
#include <LibJS/Runtime/Object.h>
|
||||||
#include <LibUnicode/Locale.h>
|
#include <LibUnicode/Locale.h>
|
||||||
|
#include <LibUnicode/RelativeTimeFormat.h>
|
||||||
|
|
||||||
namespace JS::Intl {
|
namespace JS::Intl {
|
||||||
|
|
||||||
|
@ -65,6 +67,20 @@ private:
|
||||||
NumberFormat* m_number_format { nullptr }; // [[NumberFormat]]
|
NumberFormat* m_number_format { nullptr }; // [[NumberFormat]]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct PatternPartitionWithUnit : public PatternPartition {
|
||||||
|
PatternPartitionWithUnit(StringView type, String value, StringView unit_string = {})
|
||||||
|
: PatternPartition(type, move(value))
|
||||||
|
, unit(unit_string)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
StringView unit;
|
||||||
|
};
|
||||||
|
|
||||||
ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(GlobalObject& global_object, RelativeTimeFormat& relative_time_format, Value locales_value, Value options_value);
|
ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(GlobalObject& global_object, RelativeTimeFormat& relative_time_format, Value locales_value, Value options_value);
|
||||||
|
ThrowCompletionOr<Unicode::TimeUnit> singular_relative_time_unit(GlobalObject& global_object, StringView unit);
|
||||||
|
ThrowCompletionOr<Vector<PatternPartitionWithUnit>> partition_relative_time_pattern(GlobalObject& global_object, RelativeTimeFormat& relative_time_format, double value, StringView unit);
|
||||||
|
Vector<PatternPartitionWithUnit> make_parts_list(StringView pattern, StringView unit, Vector<PatternPartition> parts);
|
||||||
|
ThrowCompletionOr<String> format_relative_time(GlobalObject& global_object, RelativeTimeFormat& relative_time_format, double value, StringView unit);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,28 @@ void RelativeTimeFormatPrototype::initialize(GlobalObject& global_object)
|
||||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.RelativeTimeFormat"sv), Attribute::Configurable);
|
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.RelativeTimeFormat"sv), Attribute::Configurable);
|
||||||
|
|
||||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||||
|
define_native_function(vm.names.format, format, 2, attr);
|
||||||
define_native_function(vm.names.resolvedOptions, resolved_options, 0, attr);
|
define_native_function(vm.names.resolvedOptions, resolved_options, 0, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 17.4.3 Intl.RelativeTimeFormat.prototype.format ( value, unit ), https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype.format
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::format)
|
||||||
|
{
|
||||||
|
// 1. Let relativeTimeFormat be the this value.
|
||||||
|
// 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]).
|
||||||
|
auto* relative_time_format = TRY(typed_this_object(global_object));
|
||||||
|
|
||||||
|
// 3. Let value be ? ToNumber(value).
|
||||||
|
auto value = TRY(vm.argument(0).to_number(global_object));
|
||||||
|
|
||||||
|
// 4. Let unit be ? ToString(unit).
|
||||||
|
auto unit = TRY(vm.argument(1).to_string(global_object));
|
||||||
|
|
||||||
|
// 5. Return ? FormatRelativeTime(relativeTimeFormat, value, unit).
|
||||||
|
auto formatted = TRY(format_relative_time(global_object, *relative_time_format, value.as_double(), unit));
|
||||||
|
return js_string(vm, move(formatted));
|
||||||
|
}
|
||||||
|
|
||||||
// 17.4.5 Intl.RelativeTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions
|
// 17.4.5 Intl.RelativeTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions
|
||||||
JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options)
|
JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,7 @@ public:
|
||||||
virtual ~RelativeTimeFormatPrototype() override = default;
|
virtual ~RelativeTimeFormatPrototype() override = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(format);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(resolved_options);
|
JS_DECLARE_NATIVE_FUNCTION(resolved_options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,432 @@
|
||||||
|
describe("errors", () => {
|
||||||
|
test("called on non-RelativeimeFormat object", () => {
|
||||||
|
expect(() => {
|
||||||
|
Intl.RelativeTimeFormat.prototype.format(1);
|
||||||
|
}).toThrowWithMessage(TypeError, "Not an object of type Intl.RelativeTimeFormat");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("called with value that cannot be converted to a number", () => {
|
||||||
|
expect(() => {
|
||||||
|
new Intl.RelativeTimeFormat().format(Symbol.hasInstance, "year");
|
||||||
|
}).toThrowWithMessage(TypeError, "Cannot convert symbol to number");
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
new Intl.RelativeTimeFormat().format(1n, "year");
|
||||||
|
}).toThrowWithMessage(TypeError, "Cannot convert BigInt to number");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("called with unit that cannot be converted to a number", () => {
|
||||||
|
expect(() => {
|
||||||
|
new Intl.RelativeTimeFormat().format(1, Symbol.hasInstance);
|
||||||
|
}).toThrowWithMessage(TypeError, "Cannot convert symbol to string");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("called with non-finite value", () => {
|
||||||
|
expect(() => {
|
||||||
|
new Intl.RelativeTimeFormat().format(Infinity, "year");
|
||||||
|
}).toThrowWithMessage(RangeError, "Number must not be NaN or Infinity");
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
new Intl.RelativeTimeFormat().format(-Infinity, "year");
|
||||||
|
}).toThrowWithMessage(RangeError, "Number must not be NaN or Infinity");
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
new Intl.RelativeTimeFormat().format(NaN, "year");
|
||||||
|
}).toThrowWithMessage(RangeError, "Number must not be NaN or Infinity");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("called with non-sanctioned unit", () => {
|
||||||
|
expect(() => {
|
||||||
|
new Intl.RelativeTimeFormat().format(1);
|
||||||
|
}).toThrowWithMessage(RangeError, "Unit undefined is not a valid time unit");
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
new Intl.RelativeTimeFormat().format(1, null);
|
||||||
|
}).toThrowWithMessage(RangeError, "Unit null is not a valid time unit");
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
new Intl.RelativeTimeFormat().format(1, "hello!");
|
||||||
|
}).toThrowWithMessage(RangeError, "Unit hello! is not a valid time unit");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
let formatters = {};
|
||||||
|
|
||||||
|
["en", "ar"].forEach(locale => {
|
||||||
|
formatters[locale] = {};
|
||||||
|
|
||||||
|
["long", "short", "narrow"].forEach(style => {
|
||||||
|
formatters[locale][style] = {};
|
||||||
|
|
||||||
|
["always", "auto"].forEach(numeric => {
|
||||||
|
formatters[locale][style][numeric] = new Intl.RelativeTimeFormat(locale, {
|
||||||
|
style: style,
|
||||||
|
numeric: numeric,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function runTest(unit, style, numeric, en, ar) {
|
||||||
|
const pluralUnit = `${unit}s`;
|
||||||
|
|
||||||
|
[-2, -1, -0, 0, 1, 2].forEach((value, i) => {
|
||||||
|
expect(formatters["en"][style][numeric].format(value, unit)).toBe(en[i]);
|
||||||
|
expect(formatters["ar"][style][numeric].format(value, unit)).toBe(ar[i]);
|
||||||
|
|
||||||
|
expect(formatters["en"][style][numeric].format(value, pluralUnit)).toBe(en[i]);
|
||||||
|
expect(formatters["ar"][style][numeric].format(value, pluralUnit)).toBe(ar[i]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("second", () => {
|
||||||
|
test("style=long, numeric=always", () => {
|
||||||
|
const en = [ "2 seconds ago", "1 second ago", "0 seconds ago", "in 0 seconds", "in 1 second", "in 2 seconds" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ثانيتين", "قبل ثانية واحدة", "قبل ٠ ثانية", "خلال ٠ ثانية", "خلال ثانية واحدة", "خلال ثانيتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("second", "long", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=always", () => {
|
||||||
|
const en = [ "2 sec. ago", "1 sec. ago", "0 sec. ago", "in 0 sec.", "in 1 sec.", "in 2 sec." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ثانيتين", "قبل ثانية واحدة", "قبل ٠ ثانية", "خلال ٠ ثانية", "خلال ثانية واحدة", "خلال ثانيتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("second", "short", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=always", () => {
|
||||||
|
const en = [ "2 sec. ago", "1 sec. ago", "0 sec. ago", "in 0 sec.", "in 1 sec.", "in 2 sec." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ثانيتين", "قبل ثانية واحدة", "قبل ٠ ثانية", "خلال ٠ ثانية", "خلال ثانية واحدة", "خلال ثانيتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("second", "narrow", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=long, numeric=auto", () => {
|
||||||
|
const en = [ "2 seconds ago", "1 second ago", "now", "now", "in 1 second", "in 2 seconds" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ثانيتين", "قبل ثانية واحدة", "الآن", "الآن", "خلال ثانية واحدة", "خلال ثانيتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("second", "long", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=auto", () => {
|
||||||
|
const en = [ "2 sec. ago", "1 sec. ago", "now", "now", "in 1 sec.", "in 2 sec." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ثانيتين", "قبل ثانية واحدة", "الآن", "الآن", "خلال ثانية واحدة", "خلال ثانيتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("second", "short", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=auto", () => {
|
||||||
|
const en = [ "2 sec. ago", "1 sec. ago", "now", "now", "in 1 sec.", "in 2 sec." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ثانيتين", "قبل ثانية واحدة", "الآن", "الآن", "خلال ثانية واحدة", "خلال ثانيتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("second", "narrow", "auto", en, ar);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("minute", () => {
|
||||||
|
test("style=long, numeric=always", () => {
|
||||||
|
const en = [ "2 minutes ago", "1 minute ago", "0 minutes ago", "in 0 minutes", "in 1 minute", "in 2 minutes" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل دقيقتين", "قبل دقيقة واحدة", "قبل ٠ دقيقة", "خلال ٠ دقيقة", "خلال دقيقة واحدة", "خلال دقيقتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("minute", "long", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=always", () => {
|
||||||
|
const en = [ "2 min. ago", "1 min. ago", "0 min. ago", "in 0 min.", "in 1 min.", "in 2 min." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل دقيقتين", "قبل دقيقة واحدة", "قبل ٠ دقيقة", "خلال ٠ دقيقة", "خلال دقيقة واحدة", "خلال دقيقتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("minute", "short", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=always", () => {
|
||||||
|
const en = [ "2 min. ago", "1 min. ago", "0 min. ago", "in 0 min.", "in 1 min.", "in 2 min." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل دقيقتين", "قبل دقيقة واحدة", "قبل ٠ دقيقة", "خلال ٠ دقيقة", "خلال دقيقة واحدة", "خلال دقيقتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("minute", "narrow", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=long, numeric=auto", () => {
|
||||||
|
const en = [ "2 minutes ago", "1 minute ago", "this minute", "this minute", "in 1 minute", "in 2 minutes" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل دقيقتين", "قبل دقيقة واحدة", "هذه الدقيقة", "هذه الدقيقة", "خلال دقيقة واحدة", "خلال دقيقتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("minute", "long", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=auto", () => {
|
||||||
|
const en = [ "2 min. ago", "1 min. ago", "this minute", "this minute", "in 1 min.", "in 2 min." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل دقيقتين", "قبل دقيقة واحدة", "هذه الدقيقة", "هذه الدقيقة", "خلال دقيقة واحدة", "خلال دقيقتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("minute", "short", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=auto", () => {
|
||||||
|
const en = [ "2 min. ago", "1 min. ago", "this minute", "this minute", "in 1 min.", "in 2 min." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل دقيقتين", "قبل دقيقة واحدة", "هذه الدقيقة", "هذه الدقيقة", "خلال دقيقة واحدة", "خلال دقيقتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("minute", "narrow", "auto", en, ar);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("hour", () => {
|
||||||
|
test("style=long, numeric=always", () => {
|
||||||
|
const en = [ "2 hours ago", "1 hour ago", "0 hours ago", "in 0 hours", "in 1 hour", "in 2 hours" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ساعتين", "قبل ساعة واحدة", "قبل ٠ ساعة", "خلال ٠ ساعة", "خلال ساعة واحدة", "خلال ساعتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("hour", "long", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=always", () => {
|
||||||
|
const en = [ "2 hr. ago", "1 hr. ago", "0 hr. ago", "in 0 hr.", "in 1 hr.", "in 2 hr." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ساعتين", "قبل ساعة واحدة", "قبل ٠ ساعة", "خلال ٠ ساعة", "خلال ساعة واحدة", "خلال ساعتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("hour", "short", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=always", () => {
|
||||||
|
const en = [ "2 hr. ago", "1 hr. ago", "0 hr. ago", "in 0 hr.", "in 1 hr.", "in 2 hr." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ساعتين", "قبل ساعة واحدة", "قبل ٠ ساعة", "خلال ٠ ساعة", "خلال ساعة واحدة", "خلال ساعتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("hour", "narrow", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=long, numeric=auto", () => {
|
||||||
|
const en = [ "2 hours ago", "1 hour ago", "this hour", "this hour", "in 1 hour", "in 2 hours" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ساعتين", "قبل ساعة واحدة", "الساعة الحالية", "الساعة الحالية", "خلال ساعة واحدة", "خلال ساعتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("hour", "long", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=auto", () => {
|
||||||
|
const en = [ "2 hr. ago", "1 hr. ago", "this hour", "this hour", "in 1 hr.", "in 2 hr." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ساعتين", "قبل ساعة واحدة", "الساعة الحالية", "الساعة الحالية", "خلال ساعة واحدة", "خلال ساعتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("hour", "short", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=auto", () => {
|
||||||
|
const en = [ "2 hr. ago", "1 hr. ago", "this hour", "this hour", "in 1 hr.", "in 2 hr." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ساعتين", "قبل ساعة واحدة", "الساعة الحالية", "الساعة الحالية", "خلال ساعة واحدة", "خلال ساعتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("hour", "narrow", "auto", en, ar);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("day", () => {
|
||||||
|
test("style=long, numeric=always", () => {
|
||||||
|
const en = [ "2 days ago", "1 day ago", "0 days ago", "in 0 days", "in 1 day", "in 2 days" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل يومين", "قبل يوم واحد", "قبل ٠ يوم", "خلال ٠ يوم", "خلال يوم واحد", "خلال يومين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("day", "long", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=always", () => {
|
||||||
|
const en = [ "2 days ago", "1 day ago", "0 days ago", "in 0 days", "in 1 day", "in 2 days" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل يومين", "قبل يوم واحد", "قبل ٠ يوم", "خلال ٠ يوم", "خلال يوم واحد", "خلال يومين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("day", "short", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=always", () => {
|
||||||
|
const en = [ "2 days ago", "1 day ago", "0 days ago", "in 0 days", "in 1 day", "in 2 days" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل يومين", "قبل يوم واحد", "قبل ٠ يوم", "خلال ٠ يوم", "خلال يوم واحد", "خلال يومين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("day", "narrow", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=long, numeric=auto", () => {
|
||||||
|
const en = [ "2 days ago", "yesterday", "today", "today", "tomorrow", "in 2 days" ]; // prettier-ignore
|
||||||
|
const ar = [ "أول أمس", "أمس", "اليوم", "اليوم", "غدًا", "بعد الغد" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("day", "long", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=auto", () => {
|
||||||
|
const en = [ "2 days ago", "yesterday", "today", "today", "tomorrow", "in 2 days" ]; // prettier-ignore
|
||||||
|
const ar = [ "أول أمس", "أمس", "اليوم", "اليوم", "غدًا", "بعد الغد" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("day", "short", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=auto", () => {
|
||||||
|
const en = [ "2 days ago", "yesterday", "today", "today", "tomorrow", "in 2 days" ]; // prettier-ignore
|
||||||
|
const ar = [ "أول أمس", "أمس", "اليوم", "اليوم", "غدًا", "بعد الغد" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("day", "narrow", "auto", en, ar);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("week", () => {
|
||||||
|
test("style=long, numeric=always", () => {
|
||||||
|
const en = [ "2 weeks ago", "1 week ago", "0 weeks ago", "in 0 weeks", "in 1 week", "in 2 weeks" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل أسبوعين", "قبل أسبوع واحد", "قبل ٠ أسبوع", "خلال ٠ أسبوع", "خلال أسبوع واحد", "خلال أسبوعين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("week", "long", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=always", () => {
|
||||||
|
const en = [ "2 wk. ago", "1 wk. ago", "0 wk. ago", "in 0 wk.", "in 1 wk.", "in 2 wk." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل أسبوعين", "قبل أسبوع واحد", "قبل ٠ أسبوع", "خلال ٠ أسبوع", "خلال أسبوع واحد", "خلال ٢ أسبوعين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("week", "short", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=always", () => {
|
||||||
|
const en = [ "2 wk. ago", "1 wk. ago", "0 wk. ago", "in 0 wk.", "in 1 wk.", "in 2 wk." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل أسبوعين", "قبل أسبوع واحد", "قبل ٠ أسبوع", "خلال ٠ أسبوع", "خلال أسبوع واحد", "خلال أسبوعين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("week", "narrow", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=long, numeric=auto", () => {
|
||||||
|
const en = [ "2 weeks ago", "last week", "this week", "this week", "next week", "in 2 weeks" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل أسبوعين", "الأسبوع الماضي", "هذا الأسبوع", "هذا الأسبوع", "الأسبوع القادم", "خلال أسبوعين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("week", "long", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=auto", () => {
|
||||||
|
const en = [ "2 wk. ago", "last wk.", "this wk.", "this wk.", "next wk.", "in 2 wk." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل أسبوعين", "الأسبوع الماضي", "هذا الأسبوع", "هذا الأسبوع", "الأسبوع القادم", "خلال ٢ أسبوعين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("week", "short", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=auto", () => {
|
||||||
|
const en = [ "2 wk. ago", "last wk.", "this wk.", "this wk.", "next wk.", "in 2 wk." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل أسبوعين", "الأسبوع الماضي", "هذا الأسبوع", "هذا الأسبوع", "الأسبوع القادم", "خلال أسبوعين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("week", "narrow", "auto", en, ar);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("month", () => {
|
||||||
|
test("style=long, numeric=always", () => {
|
||||||
|
const en = [ "2 months ago", "1 month ago", "0 months ago", "in 0 months", "in 1 month", "in 2 months" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل شهرين", "قبل شهر واحد", "قبل ٠ شهر", "خلال ٠ شهر", "خلال شهر واحد", "خلال شهرين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("month", "long", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=always", () => {
|
||||||
|
const en = [ "2 mo. ago", "1 mo. ago", "0 mo. ago", "in 0 mo.", "in 1 mo.", "in 2 mo." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل شهرين", "قبل شهر واحد", "قبل ٠ شهر", "خلال ٠ شهر", "خلال شهر واحد", "خلال شهرين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("month", "short", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=always", () => {
|
||||||
|
const en = [ "2 mo. ago", "1 mo. ago", "0 mo. ago", "in 0 mo.", "in 1 mo.", "in 2 mo." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل شهرين", "قبل شهر واحد", "قبل ٠ شهر", "خلال ٠ شهر", "خلال شهر واحد", "خلال شهرين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("month", "narrow", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=long, numeric=auto", () => {
|
||||||
|
const en = [ "2 months ago", "last month", "this month", "this month", "next month", "in 2 months" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل شهرين", "الشهر الماضي", "هذا الشهر", "هذا الشهر", "الشهر القادم", "خلال شهرين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("month", "long", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=auto", () => {
|
||||||
|
const en = [ "2 mo. ago", "last mo.", "this mo.", "this mo.", "next mo.", "in 2 mo." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل شهرين", "الشهر الماضي", "هذا الشهر", "هذا الشهر", "الشهر القادم", "خلال شهرين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("month", "short", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=auto", () => {
|
||||||
|
const en = [ "2 mo. ago", "last mo.", "this mo.", "this mo.", "next mo.", "in 2 mo." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل شهرين", "الشهر الماضي", "هذا الشهر", "هذا الشهر", "الشهر القادم", "خلال شهرين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("month", "narrow", "auto", en, ar);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("quarter", () => {
|
||||||
|
test("style=long, numeric=always", () => {
|
||||||
|
const en = [ "2 quarters ago", "1 quarter ago", "0 quarters ago", "in 0 quarters", "in 1 quarter", "in 2 quarters" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ربعي سنة", "قبل ربع سنة واحد", "قبل ٠ ربع سنة", "خلال ٠ ربع سنة", "خلال ربع سنة واحد", "خلال ربعي سنة" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("quarter", "long", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=always", () => {
|
||||||
|
const en = [ "2 qtrs. ago", "1 qtr. ago", "0 qtrs. ago", "in 0 qtrs.", "in 1 qtr.", "in 2 qtrs." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ربعي سنة", "قبل ربع سنة واحد", "قبل ٠ ربع سنة", "خلال ٠ ربع سنة", "خلال ربع سنة واحد", "خلال ربعي سنة" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("quarter", "short", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=always", () => {
|
||||||
|
const en = [ "2 qtrs. ago", "1 qtr. ago", "0 qtrs. ago", "in 0 qtrs.", "in 1 qtr.", "in 2 qtrs." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ربعي سنة", "قبل ربع سنة واحد", "قبل ٠ ربع سنة", "خلال ٠ ربع سنة", "خلال ربع سنة واحد", "خلال ربعي سنة" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("quarter", "narrow", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=long, numeric=auto", () => {
|
||||||
|
const en = [ "2 quarters ago", "last quarter", "this quarter", "this quarter", "next quarter", "in 2 quarters" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ربعي سنة", "الربع الأخير", "هذا الربع", "هذا الربع", "الربع القادم", "خلال ربعي سنة" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("quarter", "long", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=auto", () => {
|
||||||
|
const en = [ "2 qtrs. ago", "last qtr.", "this qtr.", "this qtr.", "next qtr.", "in 2 qtrs." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ربعي سنة", "الربع الأخير", "هذا الربع", "هذا الربع", "الربع القادم", "خلال ربعي سنة" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("quarter", "short", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=auto", () => {
|
||||||
|
const en = [ "2 qtrs. ago", "last qtr.", "this qtr.", "this qtr.", "next qtr.", "in 2 qtrs." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل ربعي سنة", "الربع الأخير", "هذا الربع", "هذا الربع", "الربع القادم", "خلال ربعي سنة" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("quarter", "narrow", "auto", en, ar);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("year", () => {
|
||||||
|
test("style=long, numeric=always", () => {
|
||||||
|
const en = [ "2 years ago", "1 year ago", "0 years ago", "in 0 years", "in 1 year", "in 2 years" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل سنتين", "قبل سنة واحدة", "قبل ٠ سنة", "خلال ٠ سنة", "خلال سنة واحدة", "خلال سنتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("year", "long", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=always", () => {
|
||||||
|
const en = [ "2 yr. ago", "1 yr. ago", "0 yr. ago", "in 0 yr.", "in 1 yr.", "in 2 yr." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل سنتين", "قبل سنة واحدة", "قبل ٠ سنة", "خلال ٠ سنة", "خلال سنة واحدة", "خلال سنتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("year", "short", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=always", () => {
|
||||||
|
const en = [ "2 yr. ago", "1 yr. ago", "0 yr. ago", "in 0 yr.", "in 1 yr.", "in 2 yr." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل سنتين", "قبل سنة واحدة", "قبل ٠ سنة", "خلال ٠ سنة", "خلال سنة واحدة", "خلال سنتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("year", "narrow", "always", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=long, numeric=auto", () => {
|
||||||
|
const en = [ "2 years ago", "last year", "this year", "this year", "next year", "in 2 years" ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل سنتين", "السنة الماضية", "السنة الحالية", "السنة الحالية", "السنة القادمة", "خلال سنتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("year", "long", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=short, numeric=auto", () => {
|
||||||
|
const en = [ "2 yr. ago", "last yr.", "this yr.", "this yr.", "next yr.", "in 2 yr." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل سنتين", "السنة الماضية", "السنة الحالية", "السنة الحالية", "السنة القادمة", "خلال سنتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("year", "short", "auto", en, ar);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("style=narrow, numeric=auto", () => {
|
||||||
|
const en = [ "2 yr. ago", "last yr.", "this yr.", "this yr.", "next yr.", "in 2 yr." ]; // prettier-ignore
|
||||||
|
const ar = [ "قبل سنتين", "السنة الماضية", "السنة الحالية", "السنة الحالية", "السنة القادمة", "خلال سنتين" ]; // prettier-ignore
|
||||||
|
|
||||||
|
runTest("year", "narrow", "auto", en, ar);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue