mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
LibJS: Use MaximumTemporalDurationRoundingIncrement in two more places
This is an editorial change in the Temporal spec.
See: de582e2
This commit is contained in:
parent
6c82c9df79
commit
30328d74d0
2 changed files with 12 additions and 39 deletions
|
@ -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
|
// 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)
|
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
|
// 1. If smallestUnit is "day", then
|
||||||
if (smallest_unit == "day"sv) {
|
if (smallest_unit == "day"sv) {
|
||||||
// a. Let maximum be 1.
|
// a. Let maximum be 1.
|
||||||
maximum = 1;
|
maximum = 1;
|
||||||
}
|
}
|
||||||
// 2. Else if smallestUnit is "hour", then
|
// 2. Else,
|
||||||
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,
|
|
||||||
else {
|
else {
|
||||||
// a. Assert: smallestUnit is "millisecond", "microsecond", or "nanosecond".
|
// a. Let maximum be ! MaximumTemporalDurationRoundingIncrement(smallestUnit).
|
||||||
VERIFY(smallest_unit.is_one_of("millisecond"sv, "microsecond"sv, "nanosecond"sv));
|
// b. Assert: maximum is not undefined.
|
||||||
|
maximum = *maximum_temporal_duration_rounding_increment(smallest_unit);
|
||||||
// b. Let maximum be 1000.
|
|
||||||
maximum = 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Return ? ToTemporalRoundingIncrement(normalizedOptions, maximum, false).
|
// 3. Return ? ToTemporalRoundingIncrement(normalizedOptions, maximum, false).
|
||||||
return to_temporal_rounding_increment(global_object, normalized_options, maximum, false);
|
return to_temporal_rounding_increment(global_object, normalized_options, maximum, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -299,31 +299,16 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::round)
|
||||||
// 7. Let roundingMode be ? ToTemporalRoundingMode(roundTo, "halfExpand").
|
// 7. Let roundingMode be ? ToTemporalRoundingMode(roundTo, "halfExpand").
|
||||||
auto rounding_mode = TRY(to_temporal_rounding_mode(global_object, *round_to, "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
|
// 9. Let roundingIncrement be ? ToTemporalRoundingIncrement(roundTo, maximum, false).
|
||||||
if (smallest_unit == "hour"sv) {
|
auto rounding_increment = TRY(to_temporal_rounding_increment(global_object, *round_to, *maximum, false));
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 11. Let roundingIncrement be ? ToTemporalRoundingIncrement(roundTo, maximum, false).
|
// 10. Let result be ! RoundTime(temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], roundingIncrement, smallestUnit, roundingMode).
|
||||||
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).
|
|
||||||
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);
|
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));
|
return TRY(create_temporal_time(global_object, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue