diff options
author | Linus Groh <mail@linusgroh.de> | 2022-05-07 00:13:14 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-05-08 00:07:58 +0200 |
commit | cabcdd838b29dd87a157cab1149258d53a871ec5 (patch) | |
tree | 31f679f594ece21728f0eb89eb1f307a91330df5 /Userland/Libraries | |
parent | a216c0b6df0c0c4e146b5f9110d16400c1a1afe7 (diff) | |
download | serenity-cabcdd838b29dd87a157cab1149258d53a871ec5.zip |
LibJS: Remove ToISODayOfYear
This is an editorial change in the Temporal spec.
See: https://github.com/tc39/proposal-temporal/commit/6117d90
Diffstat (limited to 'Userland/Libraries')
3 files changed, 20 insertions, 30 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp index 3f382206a4..57827e78a4 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp @@ -637,22 +637,7 @@ u8 to_iso_day_of_week(i32 year, u8 month, u8 day) return day_of_week == 0 ? 7 : day_of_week; } -// 12.2.31 ToISODayOfYear ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisodayofyear -u16 to_iso_day_of_year(i32 year, u8 month, u8 day) -{ - // 1. Assert: year is an integer. - // 2. Assert: month is an integer. - // 3. Assert: day is an integer. - - // 4. Let date be the date given by year, month, and day. - // 5. Return date's ordinal date in the year according to ISO-8601 as an integer. - u16 days = day; - for (u8 i = month - 1; i > 0; --i) - days += iso_days_in_month(year, i); - return days; -} - -// 12.2.32 ToISOWeekOfYear ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisoweekofyear +// 12.2.31 ToISOWeekOfYear ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisoweekofyear u8 to_iso_week_of_year(i32 year, u8 month, u8 day) { // 1. Assert: year is an integer. @@ -661,7 +646,7 @@ u8 to_iso_week_of_year(i32 year, u8 month, u8 day) // 4. Let date be the date given by year, month, and day. // 5. Return date's week number according to ISO-8601 as an integer. - auto day_of_year = to_iso_day_of_year(year, month, day); + auto day_of_year = day_within_year(make_date(make_day(year, month - 1, day), 0)) + 1; auto day_of_week = to_iso_day_of_week(year, month, day); auto week = (day_of_year - day_of_week + 10) / 7; @@ -684,7 +669,7 @@ u8 to_iso_week_of_year(i32 year, u8 month, u8 day) return week; } -// 12.2.33 BuildISOMonthCode ( month ), https://tc39.es/proposal-temporal/#sec-buildisomonthcode +// 12.2.32 BuildISOMonthCode ( month ), https://tc39.es/proposal-temporal/#sec-buildisomonthcode String build_iso_month_code(u8 month) { // 1. Let numberPart be ToZeroPaddedDecimalString(month, 2). @@ -692,7 +677,7 @@ String build_iso_month_code(u8 month) return String::formatted("M{:02}", month); } -// 12.2.34 ResolveISOMonth ( fields ), https://tc39.es/proposal-temporal/#sec-temporal-resolveisomonth +// 12.2.33 ResolveISOMonth ( fields ), https://tc39.es/proposal-temporal/#sec-temporal-resolveisomonth ThrowCompletionOr<double> resolve_iso_month(GlobalObject& global_object, Object const& fields) { auto& vm = global_object.vm(); @@ -752,7 +737,7 @@ ThrowCompletionOr<double> resolve_iso_month(GlobalObject& global_object, Object return number_part_integer; } -// 12.2.35 ISODateFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isodatefromfields +// 12.2.34 ISODateFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isodatefromfields ThrowCompletionOr<ISODate> iso_date_from_fields(GlobalObject& global_object, Object const& fields, Object const& options) { auto& vm = global_object.vm(); @@ -786,7 +771,7 @@ ThrowCompletionOr<ISODate> iso_date_from_fields(GlobalObject& global_object, Obj return regulate_iso_date(global_object, year.as_double(), month, day.as_double(), overflow); } -// 12.2.36 ISOYearMonthFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isoyearmonthfromfields +// 12.2.35 ISOYearMonthFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isoyearmonthfromfields ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(GlobalObject& global_object, Object const& fields, Object const& options) { auto& vm = global_object.vm(); @@ -816,7 +801,7 @@ ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(GlobalObject& global_ return ISOYearMonth { .year = result.year, .month = result.month, .reference_iso_day = 1 }; } -// 12.2.37 ISOMonthDayFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthdayfromfields +// 12.2.36 ISOMonthDayFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthdayfromfields ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(GlobalObject& global_object, Object const& fields, Object const& options) { auto& vm = global_object.vm(); @@ -874,7 +859,7 @@ ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(GlobalObject& global_ob return ISOMonthDay { .month = result->month, .day = result->day, .reference_iso_year = reference_iso_year }; } -// 12.2.38 ISOYear ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isoyear +// 12.2.37 ISOYear ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isoyear i32 iso_year(Object& temporal_object) { // 1. Assert: temporalObject has an [[ISOYear]] internal slot. @@ -892,7 +877,7 @@ i32 iso_year(Object& temporal_object) VERIFY_NOT_REACHED(); } -// 12.2.39 ISOMonth ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonth +// 12.2.38 ISOMonth ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonth u8 iso_month(Object& temporal_object) { // 1. Assert: temporalObject has an [[ISOMonth]] internal slot. @@ -910,7 +895,7 @@ u8 iso_month(Object& temporal_object) VERIFY_NOT_REACHED(); } -// 12.2.40 ISOMonthCode ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthcode +// 12.2.39 ISOMonthCode ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthcode String iso_month_code(Object& temporal_object) { // 1. Assert: temporalObject has an [[ISOMonth]] internal slot. @@ -928,7 +913,7 @@ String iso_month_code(Object& temporal_object) VERIFY_NOT_REACHED(); } -// 12.2.41 ISODay ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthcode +// 12.2.40 ISODay ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthcode u8 iso_day(Object& temporal_object) { // 1. Assert: temporalObject has an [[ISODay]] internal slot. @@ -946,7 +931,7 @@ u8 iso_day(Object& temporal_object) VERIFY_NOT_REACHED(); } -// 12.2.42 DefaultMergeFields ( fields, additionalFields ), https://tc39.es/proposal-temporal/#sec-temporal-defaultmergefields +// 12.2.41 DefaultMergeFields ( fields, additionalFields ), https://tc39.es/proposal-temporal/#sec-temporal-defaultmergefields ThrowCompletionOr<Object*> default_merge_fields(GlobalObject& global_object, Object const& fields, Object const& additional_fields) { auto& vm = global_object.vm(); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h index 1672b44e76..3ef0ce9907 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h @@ -64,7 +64,6 @@ ThrowCompletionOr<bool> calendar_equals(GlobalObject&, Object& one, Object& two) ThrowCompletionOr<Object*> consolidate_calendars(GlobalObject&, Object& one, Object& two); u8 iso_days_in_month(i32 year, u8 month); u8 to_iso_day_of_week(i32 year, u8 month, u8 day); -u16 to_iso_day_of_year(i32 year, u8 month, u8 day); u8 to_iso_week_of_year(i32 year, u8 month, u8 day); String build_iso_month_code(u8 month); ThrowCompletionOr<double> resolve_iso_month(GlobalObject&, Object const& fields); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp index 1880697237..e963b0ed6e 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp @@ -342,8 +342,14 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::day_of_year) // 4. Let temporalDate be ? ToTemporalDate(temporalDateLike). auto* temporal_date = TRY(to_temporal_date(global_object, vm.argument(0))); - // 5. Return 𝔽(! ToISODayOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])). - return Value(to_iso_day_of_year(temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day())); + // 5. Let epochDays be MakeDay(𝔽(temporalDate.[[ISOYear]]), 𝔽(temporalDate.[[ISOMonth]] - 1), 𝔽(temporalDate.[[ISODay]])). + auto epoch_days = make_day(temporal_date->iso_year(), temporal_date->iso_month() - 1, temporal_date->iso_day()); + + // 6. Assert: epochDays is finite. + VERIFY(isfinite(epoch_days)); + + // 7. Return DayWithinYear(MakeDate(epochDays, +0𝔽)) + 1𝔽. + return Value(day_within_year(make_date(epoch_days, 0)) + 1); } // 12.4.15 Temporal.Calendar.prototype.weekOfYear ( temporalDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.weekofyear |