LibJS: Add timeZoneName: "critical" option to ZonedDateTime.toString()

This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/d84937f
This commit is contained in:
Luke Wilde 2022-11-02 19:40:49 +00:00 committed by Linus Groh
parent 4a167cfbec
commit b26b18a0bc
Notes: sideshowbarker 2024-07-17 07:31:31 +09:00
3 changed files with 8 additions and 4 deletions

View file

@ -256,8 +256,8 @@ ThrowCompletionOr<String> to_show_calendar_option(VM& vm, Object const& normaliz
// 13.10 ToShowTimeZoneNameOption ( normalizedOptions ), https://tc39.es/proposal-temporal/#sec-temporal-toshowtimezonenameoption
ThrowCompletionOr<String> to_show_time_zone_name_option(VM& vm, Object const& normalized_options)
{
// 1. Return ? GetOption(normalizedOptions, "timeZoneName", "string, « "auto", "never" », "auto").
auto option = TRY(get_option(vm, normalized_options, vm.names.timeZoneName, OptionType::String, { "auto"sv, "never"sv }, "auto"sv));
// 1. Return ? GetOption(normalizedOptions, "timeZoneName", "string", « "auto", "never", "critical" », "auto").
auto option = TRY(get_option(vm, normalized_options, vm.names.timeZoneName, OptionType::String, { "auto"sv, "never"sv, "critical"sv }, "auto"sv));
VERIFY(option.is_string());
return option.as_string().string();

View file

@ -343,8 +343,11 @@ ThrowCompletionOr<String> temporal_zoned_date_time_to_string(VM& vm, ZonedDateTi
// a. Let timeZoneID be ? ToString(timeZone).
auto time_zone_id = TRY(Value(&time_zone).to_string(vm));
// b. Let timeZoneString be the string-concatenation of the code unit 0x005B (LEFT SQUARE BRACKET), timeZoneID, and the code unit 0x005D (RIGHT SQUARE BRACKET).
time_zone_string = String::formatted("[{}]", time_zone_id);
// b. If showTimeZone is "critical", let flag be "!"; else let flag be the empty String.
auto flag = show_time_zone == "critical"sv ? "!"sv : ""sv;
// c. Let timeZoneString be the string-concatenation of the code unit 0x005B (LEFT SQUARE BRACKET), flag, timeZoneID, and the code unit 0x005D (RIGHT SQUARE BRACKET).
time_zone_string = String::formatted("[{}{}]", flag, time_zone_id);
}
// 14. Let calendarString be ? MaybeFormatCalendarAnnotation(zonedDateTime.[[Calendar]], showCalendar).

View file

@ -72,6 +72,7 @@ describe("correct behavior", () => {
const values = [
["auto", "2021-11-03T01:33:05.1002003+00:00[UTC]"],
["never", "2021-11-03T01:33:05.1002003+00:00"],
["critical", "2021-11-03T01:33:05.1002003+00:00[!UTC]"],
];
for (const [timeZoneName, expected] of values) {