mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 08:28:11 +00:00
LibJS: Remove IsISOLeapYear
This is an editorial change in the Temporal spec.
See: a36bdd4
This commit is contained in:
parent
6d0d7c8fd0
commit
a216c0b6df
3 changed files with 23 additions and 45 deletions
|
@ -597,28 +597,7 @@ ThrowCompletionOr<Object*> consolidate_calendars(GlobalObject& global_object, Ob
|
|||
return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidCalendar);
|
||||
}
|
||||
|
||||
// 12.2.29 IsISOLeapYear ( year ), https://tc39.es/proposal-temporal/#sec-temporal-isisoleapyear
|
||||
bool is_iso_leap_year(i32 year)
|
||||
{
|
||||
// 1. Assert: year is an integer.
|
||||
|
||||
// 2. If year modulo 4 ≠ 0, return false.
|
||||
if (year % 4 != 0)
|
||||
return false;
|
||||
|
||||
// 3. If year modulo 400 = 0, return true.
|
||||
if (year % 400 == 0)
|
||||
return true;
|
||||
|
||||
// 4. If year modulo 100 = 0, return false.
|
||||
if (year % 100 == 0)
|
||||
return false;
|
||||
|
||||
// 5. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// 12.2.30 ISODaysInMonth ( year, month ), https://tc39.es/proposal-temporal/#sec-temporal-isodaysinmonth
|
||||
// 12.2.29 ISODaysInMonth ( year, month ), https://tc39.es/proposal-temporal/#sec-temporal-isodaysinmonth
|
||||
u8 iso_days_in_month(i32 year, u8 month)
|
||||
{
|
||||
// 1. Assert: year is an integer.
|
||||
|
@ -634,15 +613,11 @@ u8 iso_days_in_month(i32 year, u8 month)
|
|||
if (month == 4 || month == 6 || month == 9 || month == 11)
|
||||
return 30;
|
||||
|
||||
// 5. If ! IsISOLeapYear(year) is true, return 29.
|
||||
if (is_iso_leap_year(year))
|
||||
return 29;
|
||||
|
||||
// 6. Return 28.
|
||||
return 28;
|
||||
// 5. Return 28 + ℝ(InLeapYear(TimeFromYear(𝔽(year)))).
|
||||
return 28 + JS::in_leap_year(time_from_year(year));
|
||||
}
|
||||
|
||||
// 12.2.31 ToISODayOfWeek ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisodayofweek
|
||||
// 12.2.30 ToISODayOfWeek ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisodayofweek
|
||||
u8 to_iso_day_of_week(i32 year, u8 month, u8 day)
|
||||
{
|
||||
// 1. Assert: year is an integer.
|
||||
|
@ -662,7 +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.32 ToISODayOfYear ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisodayofyear
|
||||
// 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.
|
||||
|
@ -677,7 +652,7 @@ u16 to_iso_day_of_year(i32 year, u8 month, u8 day)
|
|||
return days;
|
||||
}
|
||||
|
||||
// 12.2.33 ToISOWeekOfYear ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisoweekofyear
|
||||
// 12.2.32 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.
|
||||
|
@ -696,7 +671,7 @@ u8 to_iso_week_of_year(i32 year, u8 month, u8 day)
|
|||
// year is a leap year and ends with a Friday (i.e. the first day of the given year is a
|
||||
// Saturday, or day 6), it has 53 weeks, and 52 weeks otherwise.
|
||||
auto day_of_jump = to_iso_day_of_week(year, 1, 1);
|
||||
if (day_of_jump == 5 || (is_iso_leap_year(year - 1) && day_of_jump == 6))
|
||||
if (day_of_jump == 5 || (in_leap_year(time_from_year(year - 1)) && day_of_jump == 6))
|
||||
return 53;
|
||||
else
|
||||
return 52;
|
||||
|
@ -709,7 +684,7 @@ u8 to_iso_week_of_year(i32 year, u8 month, u8 day)
|
|||
return week;
|
||||
}
|
||||
|
||||
// 12.2.34 BuildISOMonthCode ( month ), https://tc39.es/proposal-temporal/#sec-buildisomonthcode
|
||||
// 12.2.33 BuildISOMonthCode ( month ), https://tc39.es/proposal-temporal/#sec-buildisomonthcode
|
||||
String build_iso_month_code(u8 month)
|
||||
{
|
||||
// 1. Let numberPart be ToZeroPaddedDecimalString(month, 2).
|
||||
|
@ -717,7 +692,7 @@ String build_iso_month_code(u8 month)
|
|||
return String::formatted("M{:02}", month);
|
||||
}
|
||||
|
||||
// 12.2.35 ResolveISOMonth ( fields ), https://tc39.es/proposal-temporal/#sec-temporal-resolveisomonth
|
||||
// 12.2.34 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();
|
||||
|
@ -777,7 +752,7 @@ ThrowCompletionOr<double> resolve_iso_month(GlobalObject& global_object, Object
|
|||
return number_part_integer;
|
||||
}
|
||||
|
||||
// 12.2.36 ISODateFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isodatefromfields
|
||||
// 12.2.35 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();
|
||||
|
@ -811,7 +786,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.37 ISOYearMonthFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isoyearmonthfromfields
|
||||
// 12.2.36 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();
|
||||
|
@ -841,7 +816,7 @@ ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(GlobalObject& global_
|
|||
return ISOYearMonth { .year = result.year, .month = result.month, .reference_iso_day = 1 };
|
||||
}
|
||||
|
||||
// 12.2.38 ISOMonthDayFromFields ( fields, options ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthdayfromfields
|
||||
// 12.2.37 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();
|
||||
|
@ -899,7 +874,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.39 ISOYear ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isoyear
|
||||
// 12.2.38 ISOYear ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isoyear
|
||||
i32 iso_year(Object& temporal_object)
|
||||
{
|
||||
// 1. Assert: temporalObject has an [[ISOYear]] internal slot.
|
||||
|
@ -917,7 +892,7 @@ i32 iso_year(Object& temporal_object)
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
// 12.2.40 ISOMonth ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonth
|
||||
// 12.2.39 ISOMonth ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonth
|
||||
u8 iso_month(Object& temporal_object)
|
||||
{
|
||||
// 1. Assert: temporalObject has an [[ISOMonth]] internal slot.
|
||||
|
@ -935,7 +910,7 @@ u8 iso_month(Object& temporal_object)
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
// 12.2.41 ISOMonthCode ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthcode
|
||||
// 12.2.40 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.
|
||||
|
@ -953,7 +928,7 @@ String iso_month_code(Object& temporal_object)
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
// 12.2.42 ISODay ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthcode
|
||||
// 12.2.41 ISODay ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthcode
|
||||
u8 iso_day(Object& temporal_object)
|
||||
{
|
||||
// 1. Assert: temporalObject has an [[ISODay]] internal slot.
|
||||
|
@ -971,7 +946,7 @@ u8 iso_day(Object& temporal_object)
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
// 12.2.43 DefaultMergeFields ( fields, additionalFields ), https://tc39.es/proposal-temporal/#sec-temporal-defaultmergefields
|
||||
// 12.2.42 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();
|
||||
|
|
|
@ -62,7 +62,6 @@ ThrowCompletionOr<PlainMonthDay*> calendar_month_day_from_fields(GlobalObject&,
|
|||
String format_calendar_annotation(StringView id, StringView show_calendar);
|
||||
ThrowCompletionOr<bool> calendar_equals(GlobalObject&, Object& one, Object& two);
|
||||
ThrowCompletionOr<Object*> consolidate_calendars(GlobalObject&, Object& one, Object& two);
|
||||
bool is_iso_leap_year(i32 year);
|
||||
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);
|
||||
|
|
|
@ -466,8 +466,12 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::in_leap_year)
|
|||
temporal_date_like = TRY(to_temporal_date(global_object, temporal_date_like));
|
||||
}
|
||||
|
||||
// 5. Return ! IsISOLeapYear(temporalDateLike.[[ISOYear]]).
|
||||
return Value(is_iso_leap_year(iso_year(temporal_date_like.as_object())));
|
||||
// 5. If InLeapYear(TimeFromYear(𝔽(temporalDateLike.[[ISOYear]]))) is 1𝔽, return true.
|
||||
if (JS::in_leap_year(time_from_year(iso_year(temporal_date_like.as_object()))))
|
||||
return Value(true);
|
||||
|
||||
// 6. Return false.
|
||||
return Value(false);
|
||||
}
|
||||
|
||||
// 12.4.21 Temporal.Calendar.prototype.fields ( fields ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.fields
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue