diff options
author | Linus Groh <mail@linusgroh.de> | 2022-06-14 23:48:08 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-06-15 17:49:20 +0100 |
commit | 07041498f833b4093e62e46a2bb6cbe47ecf8e4e (patch) | |
tree | c940b6b398cfbe016891cf9ac687bbb935e21dee /Userland/Libraries/LibJS/Runtime/Temporal | |
parent | aaa9524a527713aef10b11a08b98c05d326ab535 (diff) | |
download | serenity-07041498f833b4093e62e46a2bb6cbe47ecf8e4e.zip |
LibJS: Inline ConstrainISOYearMonth into RegulateISOYearMonth
This is an editorial change in the Temporal spec.
See: https://github.com/tc39/proposal-temporal/commit/c97932b
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp | 29 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h | 1 |
2 files changed, 9 insertions, 21 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp index d34e996a84..23668573dd 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp @@ -103,8 +103,11 @@ ThrowCompletionOr<ISOYearMonth> regulate_iso_year_month(GlobalObject& global_obj if (!AK::is_within_range<i32>(year)) return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainYearMonth); - // a. Return ! ConstrainISOYearMonth(year, month). - return constrain_iso_year_month(year, month); + // a. Set month to the result of clamping month between 1 and 12. + month = clamp(month, 1, 12); + + // b. Return the Record { [[Year]]: year, [[Month]]: month }. + return ISOYearMonth { .year = static_cast<i32>(year), .month = static_cast<u8>(month), .reference_iso_day = 0 }; } // 4. Else, else { @@ -183,21 +186,7 @@ ISOYearMonth balance_iso_year_month(double year, double month) return ISOYearMonth { .year = static_cast<i32>(year), .month = static_cast<u8>(month), .reference_iso_day = 0 }; } -// 9.5.6 ConstrainISOYearMonth ( year, month ), https://tc39.es/proposal-temporal/#sec-temporal-constrainisoyearmonth -ISOYearMonth constrain_iso_year_month(double year, double month) -{ - // 1. Assert: year and month are integers. - VERIFY(year == trunc(year) && month == trunc(month)); - - // 2. Set month to the result of clamping month between 1 and 12. - month = clamp(month, 1, 12); - - // 3. Return the Record { [[Year]]: year, [[Month]]: month }. - // NOTE: `year` is known to be in the i32 range. - return ISOYearMonth { .year = static_cast<i32>(year), .month = static_cast<u8>(month), .reference_iso_day = 0 }; -} - -// 9.5.7 CreateTemporalYearMonth ( isoYear, isoMonth, calendar, referenceISODay [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalyearmonth +// 9.5.6 CreateTemporalYearMonth ( isoYear, isoMonth, calendar, referenceISODay [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalyearmonth ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(GlobalObject& global_object, i32 iso_year, u8 iso_month, Object& calendar, u8 reference_iso_day, FunctionObject const* new_target) { auto& vm = global_object.vm(); @@ -228,7 +217,7 @@ ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(GlobalObject& glob return object; } -// 9.5.8 TemporalYearMonthToString ( yearMonth, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporalyearmonthtostring +// 9.5.7 TemporalYearMonthToString ( yearMonth, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporalyearmonthtostring ThrowCompletionOr<String> temporal_year_month_to_string(GlobalObject& global_object, PlainYearMonth& year_month, StringView show_calendar) { // 1. Assert: Type(yearMonth) is Object. @@ -257,7 +246,7 @@ ThrowCompletionOr<String> temporal_year_month_to_string(GlobalObject& global_obj return String::formatted("{}{}", result, calendar_string); } -// 9.5.9 DifferenceTemporalPlainYearMonth ( operation, yearMonth, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalplainyearmonth +// 9.5.8 DifferenceTemporalPlainYearMonth ( operation, yearMonth, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalplainyearmonth ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(GlobalObject& global_object, DifferenceOperation operation, PlainYearMonth& year_month, Value other_value, Value options_value) { auto& vm = global_object.vm(); @@ -351,7 +340,7 @@ ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(GlobalObject& return MUST(create_temporal_duration(global_object, sign * result.years, sign * result.months, 0, 0, 0, 0, 0, 0, 0, 0)); } -// 9.5.10 AddDurationToOrSubtractDurationFromPlainYearMonth ( operation, yearMonth, temporalDurationLike, options ), https://tc39.es/proposal-temporal/#sec-temporal-addtemporalplainyearmonth +// 9.5.9 AddDurationToOrSubtractDurationFromPlainYearMonth ( operation, yearMonth, temporalDurationLike, options ), https://tc39.es/proposal-temporal/#sec-temporal-addtemporalplainyearmonth ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_plain_year_month(GlobalObject& global_object, ArithmeticOperation operation, PlainYearMonth& year_month, Value temporal_duration_like, Value options_value) { auto& vm = global_object.vm(); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h index d0245dffc5..55d66ca83d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h @@ -45,7 +45,6 @@ ThrowCompletionOr<ISOYearMonth> regulate_iso_year_month(GlobalObject&, double ye bool is_valid_iso_month(u8 month); bool iso_year_month_within_limits(i32 year, u8 month); ISOYearMonth balance_iso_year_month(double year, double month); -ISOYearMonth constrain_iso_year_month(double year, double month); ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(GlobalObject&, i32 iso_year, u8 iso_month, Object& calendar, u8 reference_iso_day, FunctionObject const* new_target = nullptr); ThrowCompletionOr<String> temporal_year_month_to_string(GlobalObject&, PlainYearMonth&, StringView show_calendar); ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(GlobalObject&, DifferenceOperation, PlainYearMonth&, Value other, Value options); |