diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index 17650de2b8..4302c9a58b 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -321,33 +321,21 @@ ThrowCompletionOr to_temporal_rounding_increment(GlobalObject& global_objec // 13.13 ToTemporalDateTimeRoundingIncrement ( normalizedOptions, smallestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldatetimeroundingincrement ThrowCompletionOr to_temporal_date_time_rounding_increment(GlobalObject& global_object, Object const& normalized_options, StringView smallest_unit) { - double maximum; + u16 maximum; // 1. If smallestUnit is "day", then if (smallest_unit == "day"sv) { // a. Let maximum be 1. maximum = 1; } - // 2. Else if smallestUnit is "hour", then - else if (smallest_unit == "hour"sv) { - // a. Let maximum be 24. - maximum = 24; - } - // 3. Else if smallestUnit is "minute" or "second", then - else if (smallest_unit.is_one_of("minute"sv, "second"sv)) { - // a. Let maximum be 60. - maximum = 60; - } - // 4. Else, + // 2. Else, else { - // a. Assert: smallestUnit is "millisecond", "microsecond", or "nanosecond". - VERIFY(smallest_unit.is_one_of("millisecond"sv, "microsecond"sv, "nanosecond"sv)); - - // b. Let maximum be 1000. - maximum = 1000; + // a. Let maximum be ! MaximumTemporalDurationRoundingIncrement(smallestUnit). + // b. Assert: maximum is not undefined. + maximum = *maximum_temporal_duration_rounding_increment(smallest_unit); } - // 5. Return ? ToTemporalRoundingIncrement(normalizedOptions, maximum, false). + // 3. Return ? ToTemporalRoundingIncrement(normalizedOptions, maximum, false). return to_temporal_rounding_increment(global_object, normalized_options, maximum, false); } diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp index c07feab515..f542effa6b 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTimePrototype.cpp @@ -299,31 +299,16 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::round) // 7. Let roundingMode be ? ToTemporalRoundingMode(roundTo, "halfExpand"). auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *round_to, "halfExpand")); - double maximum; + // 8. Let maximum be ! MaximumTemporalDurationRoundingIncrement(smallestUnit). + auto maximum = maximum_temporal_duration_rounding_increment(*smallest_unit); - // 8. If smallestUnit is "hour", then - if (smallest_unit == "hour"sv) { - // a. Let maximum be 24. - maximum = 24; - } - // 9. Else if smallestUnit is "minute" or "second", then - else if (smallest_unit == "minute"sv || smallest_unit == "second"sv) { - // a. Let maximum be 60. - maximum = 60; - } - // 10. Else, - else { - // a. Let maximum be 1000. - maximum = 1000; - } + // 9. Let roundingIncrement be ? ToTemporalRoundingIncrement(roundTo, maximum, false). + auto rounding_increment = TRY(to_temporal_rounding_increment(global_object, *round_to, *maximum, false)); - // 11. Let roundingIncrement be ? ToTemporalRoundingIncrement(roundTo, maximum, false). - auto rounding_increment = TRY(to_temporal_rounding_increment(global_object, *round_to, maximum, false)); - - // 12. Let result be ! RoundTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], roundingIncrement, smallestUnit, roundingMode). + // 10. Let result be ! RoundTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], roundingIncrement, smallestUnit, roundingMode). auto result = round_time(temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), rounding_increment, *smallest_unit, rounding_mode); - // 13. Return ? CreateTemporalTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]). + // 11. Return ? CreateTemporalTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]). return TRY(create_temporal_time(global_object, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond)); }