LibJS: Use MaximumTemporalDurationRoundingIncrement in two more places

This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/de582e2
This commit is contained in:
Linus Groh 2022-06-14 23:29:29 +01:00
parent 6c82c9df79
commit 30328d74d0
Notes: sideshowbarker 2024-07-17 18:08:55 +09:00
2 changed files with 12 additions and 39 deletions

View File

@ -321,33 +321,21 @@ ThrowCompletionOr<u64> to_temporal_rounding_increment(GlobalObject& global_objec
// 13.13 ToTemporalDateTimeRoundingIncrement ( normalizedOptions, smallestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaldatetimeroundingincrement
ThrowCompletionOr<u64> 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);
}

View File

@ -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));
}