1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:37:35 +00:00

LibJS: Move time zone annotation parsing into ParseISODateTime

This is an editorial change in the Temporal spec.

See: tc39/proposal-temporal@c410e25e47
This commit is contained in:
snooze6214 2022-10-15 03:32:18 +05:30 committed by Brian Gianforcaro
parent 135ca3fa1b
commit 1fde3737f4
3 changed files with 74 additions and 103 deletions

View file

@ -190,13 +190,10 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
auto string = TRY(item.to_string(vm));
// c. Let result be ? ParseTemporalZonedDateTimeString(string).
auto parsed_result = TRY(parse_temporal_zoned_date_time_string(vm, string));
result = TRY(parse_temporal_zoned_date_time_string(vm, string));
// NOTE: The ISODateTime struct inside parsed_result will be moved into `result` at the end of this path to avoid mismatching names.
// Thus, all remaining references to `result` in this path actually refers to `parsed_result`.
// d. Let timeZoneName be result.[[TimeZoneName]].
auto time_zone_name = parsed_result.time_zone.name;
// d. Let timeZoneName be result.[[TimeZone]].[[Name]].
auto time_zone_name = result.time_zone.name;
// e. Assert: timeZoneName is not undefined.
VERIFY(time_zone_name.has_value());
@ -211,11 +208,11 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
time_zone_name = canonicalize_time_zone_name(*time_zone_name);
}
// g. Let offsetString be result.[[TimeZoneOffsetString]].
offset_string = move(parsed_result.time_zone.offset_string);
// g. Let offsetString be result.[[TimeZone]].[[OffsetString]].
offset_string = move(result.time_zone.offset_string);
// h. If result.[[TimeZoneZ]] is true, then
if (parsed_result.time_zone.z) {
// h. If result.[[TimeZone]].[[Z]] is true, then
if (result.time_zone.z) {
// i. Set offsetBehaviour to exact.
offset_behavior = OffsetBehavior::Exact;
}
@ -229,16 +226,13 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
time_zone = MUST(create_temporal_time_zone(vm, *time_zone_name));
// k. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
auto temporal_calendar_like = parsed_result.date_time.calendar.has_value()
? js_string(vm, parsed_result.date_time.calendar.value())
auto temporal_calendar_like = result.calendar.has_value()
? js_string(vm, result.calendar.value())
: js_undefined();
calendar = TRY(to_temporal_calendar_with_iso_default(vm, temporal_calendar_like));
// l. Set matchBehaviour to match minutes.
match_behavior = MatchBehavior::MatchMinutes;
// See NOTE above about why this is done.
result = move(parsed_result.date_time);
}
// 7. Let offsetNanoseconds be 0.