From 6d5e95d6216d762ed064c36c1f734801d25b1f83 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 18 Dec 2021 17:35:06 +0000 Subject: [PATCH] LibJS: Add optional calendar to Plain{Time,YearMonth,MonthDay} prod This is a normative change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/7e58ba3 --- .../LibJS/Runtime/Temporal/ISO8601.cpp | 47 ++++++++++--------- .../LibJS/Runtime/Temporal/ISO8601.h | 2 +- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp index 0c22bd6cbd..457b70cb24 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp @@ -782,17 +782,6 @@ bool ISO8601Parser::parse_time_spec() return true; } -// https://tc39.es/proposal-temporal/#prod-Time -bool ISO8601Parser::parse_time() -{ - // Time : - // TimeSpec TimeZone[opt] - if (!parse_time_spec()) - return false; - (void)parse_time_zone(); - return true; -} - // https://tc39.es/proposal-temporal/#prod-TimeSpecSeparator bool ISO8601Parser::parse_time_spec_separator() { @@ -819,6 +808,18 @@ bool ISO8601Parser::parse_date_time() return true; } +// https://tc39.es/proposal-temporal/#prod-CalendarTime +bool ISO8601Parser::parse_calendar_time() +{ + // CalendarTime : + // TimeSpec TimeZone[opt] Calendar[opt] + if (!parse_time_spec()) + return false; + (void)parse_time_zone(); + (void)parse_calendar(); + return true; +} + // https://tc39.es/proposal-temporal/#prod-CalendarDateTime bool ISO8601Parser::parse_calendar_date_time() { @@ -1173,10 +1174,10 @@ bool ISO8601Parser::parse_temporal_month_day_string() { // TemporalMonthDayString : // DateSpecMonthDay - // DateTime - // NOTE: Reverse order here because `DateSpecMonthDay` can be a subset of `DateTime`, + // CalendarDateTime + // NOTE: Reverse order here because `DateSpecMonthDay` can be a subset of `CalendarDateTime`, // so we'd not attempt to parse that but may not exhaust the input string. - return parse_date_time() + return parse_calendar_date_time() || parse_date_spec_month_day(); } @@ -1184,12 +1185,12 @@ bool ISO8601Parser::parse_temporal_month_day_string() bool ISO8601Parser::parse_temporal_time_string() { // TemporalTimeString : - // Time - // DateTime + // CalendarTime + // CalendarDateTime // NOTE: Reverse order here because `Time` can be a subset of `DateTime`, // so we'd not attempt to parse that but may not exhaust the input string. - return parse_date_time() - || parse_time(); + return parse_calendar_date_time() + || parse_calendar_time(); } // https://tc39.es/proposal-temporal/#prod-TemporalTimeZoneIdentifier @@ -1226,10 +1227,10 @@ bool ISO8601Parser::parse_temporal_year_month_string() { // TemporalYearMonthString : // DateSpecYearMonth - // DateTime - // NOTE: Reverse order here because `DateSpecYearMonth` can be a subset of `DateTime`, + // CalendarDateTime + // NOTE: Reverse order here because `DateSpecYearMonth` can be a subset of `CalendarDateTime`, // so we'd not attempt to parse that but may not exhaust the input string. - return parse_date_time() + return parse_calendar_date_time() || parse_date_spec_year_month(); } @@ -1256,7 +1257,7 @@ bool ISO8601Parser::parse_temporal_calendar_string() // CalendarName // TemporalInstantString // CalendarDateTime - // Time + // CalendarTime // DateSpecYearMonth // DateSpecMonthDay return parse_calendar_name() @@ -1264,7 +1265,7 @@ bool ISO8601Parser::parse_temporal_calendar_string() || parse_calendar_date_time() || parse_date_spec_year_month() || parse_date_spec_month_day() - || parse_time(); + || parse_calendar_time(); } // https://tc39.es/proposal-temporal/#prod-TemporalRelativeToString diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h index efb5736f4f..0ccc5a0e7c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h @@ -124,9 +124,9 @@ public: [[nodiscard]] bool parse_calendar_name(); [[nodiscard]] bool parse_calendar(); [[nodiscard]] bool parse_time_spec(); - [[nodiscard]] bool parse_time(); [[nodiscard]] bool parse_time_spec_separator(); [[nodiscard]] bool parse_date_time(); + [[nodiscard]] bool parse_calendar_time(); [[nodiscard]] bool parse_calendar_date_time(); [[nodiscard]] bool parse_duration_whole_seconds(); [[nodiscard]] bool parse_duration_seconds_fraction();