1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:07:45 +00:00

LibJS: Port temporal_month_day_to_string() to String

This commit is contained in:
Linus Groh 2023-01-26 15:49:37 +00:00
parent d2c10f6bea
commit 2aa4fcc318
2 changed files with 8 additions and 8 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -174,7 +174,7 @@ ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(VM& vm, u8 iso_month
}
// 10.5.3 TemporalMonthDayToString ( monthDay, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporalmonthdaytostring
ThrowCompletionOr<DeprecatedString> temporal_month_day_to_string(VM& vm, PlainMonthDay& month_day, StringView show_calendar)
ThrowCompletionOr<String> temporal_month_day_to_string(VM& vm, PlainMonthDay& month_day, StringView show_calendar)
{
// 1. Assert: Type(monthDay) is Object.
// 2. Assert: monthDay has an [[InitializedTemporalMonthDay]] internal slot.
@ -182,16 +182,16 @@ ThrowCompletionOr<DeprecatedString> temporal_month_day_to_string(VM& vm, PlainMo
// 3. Let month be ToZeroPaddedDecimalString(temporalDate.[[ISOMonth]], 2).
// 4. Let day be ToZeroPaddedDecimalString(temporalDate.[[ISODay]], 2).
// 5. Let result be the string-concatenation of month, the code unit 0x002D (HYPHEN-MINUS), and day.
auto result = DeprecatedString::formatted("{:02}-{:02}", month_day.iso_month(), month_day.iso_day());
auto result = TRY_OR_THROW_OOM(vm, String::formatted("{:02}-{:02}", month_day.iso_month(), month_day.iso_day()));
// 6. Let calendarID be ? ToString(monthDay.[[Calendar]]).
auto calendar_id = TRY(Value(&month_day.calendar()).to_deprecated_string(vm));
auto calendar_id = TRY(Value(&month_day.calendar()).to_string(vm));
// 7. If showCalendar is one of "always" or "critical", or if calendarID is not "iso8601", then
if (show_calendar.is_one_of("always"sv, "critical"sv) || calendar_id != "iso8601"sv) {
// a. Let year be ! PadISOYear(monthDay.[[ISOYear]]).
// b. Set result to the string-concatenation of year, the code unit 0x002D (HYPHEN-MINUS), and result.
result = DeprecatedString::formatted("{}-{}", pad_iso_year(month_day.iso_year()), result);
result = TRY_OR_THROW_OOM(vm, String::formatted("{}-{}", pad_iso_year(month_day.iso_year()), result));
}
// 8. Let calendarString be ! FormatCalendarAnnotation(calendarID, showCalendar).
@ -199,7 +199,7 @@ ThrowCompletionOr<DeprecatedString> temporal_month_day_to_string(VM& vm, PlainMo
// 9. Set result to the string-concatenation of result and calendarString.
// 10. Return result.
return DeprecatedString::formatted("{}{}", result, calendar_string);
return TRY_OR_THROW_OOM(vm, String::formatted("{}{}", result, calendar_string));
}
}