diff options
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp | 39 |
1 files changed, 12 insertions, 27 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(); |