mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 12:08:14 +00:00
LibJS: Port iso_month_code() to String
This commit is contained in:
parent
bcca5efd5a
commit
b09522312c
3 changed files with 5 additions and 5 deletions
|
@ -748,11 +748,11 @@ YearWeekRecord to_iso_week_of_year(i32 year, u8 month, u8 day)
|
|||
}
|
||||
|
||||
// 12.2.33 ISOMonthCode ( month ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthcode
|
||||
DeprecatedString iso_month_code(u8 month)
|
||||
ThrowCompletionOr<String> iso_month_code(VM& vm, u8 month)
|
||||
{
|
||||
// 1. Let numberPart be ToZeroPaddedDecimalString(month, 2).
|
||||
// 2. Return the string-concatenation of "M" and numberPart.
|
||||
return DeprecatedString::formatted("M{:02}", month);
|
||||
return TRY_OR_THROW_OOM(vm, String::formatted("M{:02}", month));
|
||||
}
|
||||
|
||||
// 12.2.34 ResolveISOMonth ( fields ), https://tc39.es/proposal-temporal/#sec-temporal-resolveisomonth
|
||||
|
@ -804,7 +804,7 @@ ThrowCompletionOr<double> resolve_iso_month(VM& vm, Object const& fields)
|
|||
auto month_code_number = MUST(Value(PrimitiveString::create(vm, move(month_code_digits))).to_integer_or_infinity(vm));
|
||||
|
||||
// 12. Assert: SameValue(monthCode, ISOMonthCode(monthCodeNumber)) is true.
|
||||
VERIFY(month_code_string == iso_month_code(month_code_number));
|
||||
VERIFY(month_code_string.view() == TRY(iso_month_code(vm, month_code_number)));
|
||||
|
||||
// 13. If month is not undefined and SameValue(month, monthCodeNumber) is false, throw a RangeError exception.
|
||||
if (!month.is_undefined() && month.as_double() != month_code_number)
|
||||
|
|
|
@ -73,7 +73,7 @@ ThrowCompletionOr<bool> calendar_equals(VM&, Object& one, Object& two);
|
|||
ThrowCompletionOr<Object*> consolidate_calendars(VM&, Object& one, Object& two);
|
||||
u8 iso_days_in_month(i32 year, u8 month);
|
||||
YearWeekRecord to_iso_week_of_year(i32 year, u8 month, u8 day);
|
||||
DeprecatedString iso_month_code(u8 month);
|
||||
ThrowCompletionOr<String> iso_month_code(VM&, u8 month);
|
||||
ThrowCompletionOr<double> resolve_iso_month(VM&, Object const& fields);
|
||||
ThrowCompletionOr<ISODateRecord> iso_date_from_fields(VM&, Object const& fields, Object const& options);
|
||||
ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(VM&, Object const& fields, Object const& options);
|
||||
|
|
|
@ -301,7 +301,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::month_code)
|
|||
// NOTE: The assertion happens in iso_month() call.
|
||||
|
||||
// 6. Return ISOMonthCode(temporalDateLike.[[ISOMonth]]).
|
||||
return PrimitiveString::create(vm, iso_month_code(iso_month(temporal_date_like.as_object())));
|
||||
return PrimitiveString::create(vm, TRY(iso_month_code(vm, iso_month(temporal_date_like.as_object()))));
|
||||
}
|
||||
|
||||
// 12.4.12 Temporal.Calendar.prototype.day ( temporalDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.day
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue