mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-02 04:20:28 +00:00
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:
parent
4a167cfbec
commit
b26b18a0bc
Notes:
sideshowbarker
2024-07-17 07:31:31 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/b26b18a0bc Pull-request: https://github.com/SerenityOS/serenity/pull/15893 Reviewed-by: https://github.com/linusg ✅
3 changed files with 8 additions and 4 deletions
|
@ -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();
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue