1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:27:45 +00:00

LibJS: Refactor ToRelativeTemporalObject

This is an editorial change in the Temporal spec.
See: 895854d9
This commit is contained in:
Idan Horowitz 2022-10-20 00:13:26 +03:00 committed by Linus Groh
parent 8d7158025f
commit 0c61552b81

View file

@ -679,13 +679,17 @@ ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& optio
} }
} }
// 8. If timeZone is not undefined, then // 8. If timeZone is undefined, then
if (!time_zone.is_undefined()) { if (time_zone.is_undefined()) {
// a. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar).
return TRY(create_temporal_date(vm, result.year, result.month, result.day, *calendar));
}
double offset_ns; double offset_ns;
// a. If offsetBehaviour is option, then // 9. If offsetBehaviour is option, then
if (offset_behavior == OffsetBehavior::Option) { if (offset_behavior == OffsetBehavior::Option) {
// i. Set offsetString to ? ToString(offsetString). // a. Set offsetString to ? ToString(offsetString).
// NOTE: offsetString is not used after this path, so we don't need to put this into the original offset_string which is of type JS::Value. // NOTE: offsetString is not used after this path, so we don't need to put this into the original offset_string which is of type JS::Value.
auto actual_offset_string = TRY(offset_string.to_string(vm)); auto actual_offset_string = TRY(offset_string.to_string(vm));
@ -696,23 +700,19 @@ ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& optio
// c. Let offsetNs be ParseTimeZoneOffsetString(offsetString). // c. Let offsetNs be ParseTimeZoneOffsetString(offsetString).
offset_ns = parse_time_zone_offset_string(actual_offset_string); offset_ns = parse_time_zone_offset_string(actual_offset_string);
} }
// b. Else, // 10. Else,
else { else {
// i. Let offsetNs be 0. // a. Let offsetNs be 0.
offset_ns = 0; offset_ns = 0;
} }
// c. Let epochNanoseconds be ? InterpretISODateTimeOffset(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], offsetBehaviour, offsetNs, timeZone, "compatible", "reject", matchBehaviour). // 11. Let epochNanoseconds be ? InterpretISODateTimeOffset(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], offsetBehaviour, offsetNs, timeZone, "compatible", "reject", matchBehaviour).
auto* epoch_nanoseconds = TRY(interpret_iso_date_time_offset(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, offset_behavior, offset_ns, time_zone, "compatible"sv, "reject"sv, match_behavior)); auto const* epoch_nanoseconds = TRY(interpret_iso_date_time_offset(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, offset_behavior, offset_ns, time_zone, "compatible"sv, "reject"sv, match_behavior));
// d. Return ! CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar). // 12. Return ! CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar).
return MUST(create_temporal_zoned_date_time(vm, *epoch_nanoseconds, time_zone.as_object(), *calendar)); return MUST(create_temporal_zoned_date_time(vm, *epoch_nanoseconds, time_zone.as_object(), *calendar));
} }
// 9. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar).
return TRY(create_temporal_date(vm, result.year, result.month, result.day, *calendar));
}
// 13.17 LargerOfTwoTemporalUnits ( u1, u2 ), https://tc39.es/proposal-temporal/#sec-temporal-largeroftwotemporalunits // 13.17 LargerOfTwoTemporalUnits ( u1, u2 ), https://tc39.es/proposal-temporal/#sec-temporal-largeroftwotemporalunits
StringView larger_of_two_temporal_units(StringView unit1, StringView unit2) StringView larger_of_two_temporal_units(StringView unit1, StringView unit2)
{ {