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

LibJS: Implement Temporal.PlainDate.prototype.toString()

This commit is contained in:
Linus Groh 2021-08-18 21:15:04 +01:00 committed by Andreas Kling
parent 310192f918
commit 402f04c2fc
10 changed files with 164 additions and 0 deletions

View file

@ -477,6 +477,24 @@ PlainMonthDay* month_day_from_fields(GlobalObject& global_object, Object& calend
return static_cast<PlainMonthDay*>(month_day_object);
}
// 12.1.27 FormatCalendarAnnotation ( id, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-formatcalendarannotation
String format_calendar_annotation(StringView id, StringView show_calendar)
{
// 1. Assert: showCalendar is "auto", "always", or "never".
VERIFY(show_calendar == "auto"sv || show_calendar == "always"sv || show_calendar == "never"sv);
// 2. If showCalendar is "never", return the empty String.
if (show_calendar == "never"sv)
return String::empty();
// 3. If showCalendar is "auto" and id is "iso8601", return the empty String.
if (show_calendar == "auto"sv && id == "iso8601"sv)
return String::empty();
// 4. Return the string-concatenation of "[u-ca=", id, and "]".
return String::formatted("[u-ca={}]", id);
}
// 12.1.28 CalendarEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-calendarequals
bool calendar_equals(GlobalObject& global_object, Object& one, Object& two)
{