mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibJS: Implement stringification Temporal.PlainDate prototypes
This commit is contained in:
parent
a0c55f76e7
commit
9fbb5a57fa
Notes:
github-actions[bot]
2024-11-23 13:48:14 +00:00
Author: https://github.com/trflynn89
Commit: 9fbb5a57fa
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2513
Reviewed-by: https://github.com/shannonbooth ✅
7 changed files with 171 additions and 0 deletions
|
@ -255,6 +255,25 @@ String pad_iso_year(i32 year)
|
|||
return MUST(String::formatted("{}{:06}", year_sign, abs(year)));
|
||||
}
|
||||
|
||||
// 3.5.10 TemporalDateToString ( temporalDate, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporaldatetostring
|
||||
String temporal_date_to_string(PlainDate const& temporal_date, ShowCalendar show_calendar)
|
||||
{
|
||||
// 1. Let year be PadISOYear(temporalDate.[[ISODate]].[[Year]]).
|
||||
auto year = pad_iso_year(temporal_date.iso_date().year);
|
||||
|
||||
// 2. Let month be ToZeroPaddedDecimalString(temporalDate.[[ISODate]].[[Month]], 2).
|
||||
auto month = temporal_date.iso_date().month;
|
||||
|
||||
// 3. Let day be ToZeroPaddedDecimalString(temporalDate.[[ISODate]].[[Day]], 2).
|
||||
auto day = temporal_date.iso_date().day;
|
||||
|
||||
// 4. Let calendar be FormatCalendarAnnotation(temporalDate.[[Calendar]], showCalendar).
|
||||
auto calendar = format_calendar_annotation(temporal_date.calendar(), show_calendar);
|
||||
|
||||
// 5. Return the string-concatenation of year, the code unit 0x002D (HYPHEN-MINUS), month, the code unit 0x002D (HYPHEN-MINUS), day, and calendar.
|
||||
return MUST(String::formatted("{}-{:02}-{:02}{}", year, month, day, calendar));
|
||||
}
|
||||
|
||||
// 3.5.11 ISODateWithinLimits ( isoDate ), https://tc39.es/proposal-temporal/#sec-temporal-isodatewithinlimits
|
||||
bool iso_date_within_limits(ISODate iso_date)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue