summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-10-20 00:13:26 +0300
committerLinus Groh <mail@linusgroh.de>2022-10-20 00:47:42 +0200
commit0c61552b819bf924ff802c914cac5c7d6284f8a9 (patch)
treed5c1c595103a97f1b0eb2acf55419fd539dfd75d /Userland/Libraries/LibJS
parent8d7158025f99ea58048f0443a08f55cf2879f031 (diff)
downloadserenity-0c61552b819bf924ff802c914cac5c7d6284f8a9.zip
LibJS: Refactor ToRelativeTemporalObject
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/895854d9
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp56
1 files changed, 28 insertions, 28 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
index ccd6f969eb..8c026c6e08 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
@@ -679,38 +679,38 @@ ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& optio
}
}
- // 8. If timeZone is not undefined, then
- if (!time_zone.is_undefined()) {
- double offset_ns;
-
- // a. If offsetBehaviour is option, then
- if (offset_behavior == OffsetBehavior::Option) {
- // i. 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.
- auto actual_offset_string = TRY(offset_string.to_string(vm));
-
- // b. If IsTimeZoneOffsetString(offsetString) is false, throw a RangeError exception.
- if (!is_time_zone_offset_string(actual_offset_string))
- return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidTimeZoneName, actual_offset_string);
-
- // c. Let offsetNs be ParseTimeZoneOffsetString(offsetString).
- offset_ns = parse_time_zone_offset_string(actual_offset_string);
- }
- // b. Else,
- else {
- // i. Let offsetNs be 0.
- offset_ns = 0;
- }
+ // 8. If timeZone is undefined, then
+ 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;
- // 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).
- 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));
+ // 9. If offsetBehaviour is option, then
+ if (offset_behavior == OffsetBehavior::Option) {
+ // 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.
+ auto actual_offset_string = TRY(offset_string.to_string(vm));
- // d. Return ! CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar).
- return MUST(create_temporal_zoned_date_time(vm, *epoch_nanoseconds, time_zone.as_object(), *calendar));
+ // b. If IsTimeZoneOffsetString(offsetString) is false, throw a RangeError exception.
+ if (!is_time_zone_offset_string(actual_offset_string))
+ return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidTimeZoneName, actual_offset_string);
+
+ // c. Let offsetNs be ParseTimeZoneOffsetString(offsetString).
+ offset_ns = parse_time_zone_offset_string(actual_offset_string);
}
+ // 10. Else,
+ else {
+ // a. Let offsetNs be 0.
+ offset_ns = 0;
+ }
+
+ // 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 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));
- // 9. Return ? CreateTemporalDate(result.[[Year]], result.[[Month]], result.[[Day]], calendar).
- return TRY(create_temporal_date(vm, result.year, result.month, result.day, *calendar));
+ // 12. Return ! CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar).
+ return MUST(create_temporal_zoned_date_time(vm, *epoch_nanoseconds, time_zone.as_object(), *calendar));
}
// 13.17 LargerOfTwoTemporalUnits ( u1, u2 ), https://tc39.es/proposal-temporal/#sec-temporal-largeroftwotemporalunits