summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-12-18 17:50:44 +0000
committerLinus Groh <mail@linusgroh.de>2021-12-18 22:32:39 +0000
commit01eefc344a63e5b64a23d9c1c71ddc78bfcb80ef (patch)
tree85a61b8ae79af292429705f38e568e92415c3947
parent6da6da73ccc45a28f7b638f7cda67553c784e3a0 (diff)
downloadserenity-01eefc344a63e5b64a23d9c1c71ddc78bfcb80ef.zip
LibJS: Disallow date-only strings for PlainTime
This is a normative change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/b16a296
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp22
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h1
2 files changed, 20 insertions, 3 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp
index 446d34fed6..16a0053b64 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp
@@ -834,6 +834,22 @@ bool ISO8601Parser::parse_calendar_date_time()
return true;
}
+// https://tc39.es/proposal-temporal/#prod-CalendarDateTimeTimeRequired
+bool ISO8601Parser::parse_calendar_date_time_time_required()
+{
+ // CalendarDateTimeTimeRequired :
+ // Date TimeSpecSeparator TimeZone[opt] Calendar[opt]
+ StateTransaction transaction { *this };
+ if (!parse_date())
+ return false;
+ if (!parse_time_spec_separator())
+ return false;
+ (void)parse_time_zone();
+ (void)parse_calendar();
+ transaction.commit();
+ return true;
+}
+
// https://tc39.es/proposal-temporal/#prod-DurationWholeSeconds
bool ISO8601Parser::parse_duration_whole_seconds()
{
@@ -1189,10 +1205,10 @@ bool ISO8601Parser::parse_temporal_time_string()
{
// TemporalTimeString :
// CalendarTime
- // CalendarDateTime
- // NOTE: Reverse order here because `Time` can be a subset of `DateTime`,
+ // CalendarDateTimeTimeRequired
+ // NOTE: Reverse order here because `Time` can be a subset of `CalendarDateTimeTimeRequired`,
// so we'd not attempt to parse that but may not exhaust the input string.
- return parse_calendar_date_time()
+ return parse_calendar_date_time_time_required()
|| parse_calendar_time();
}
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h
index 749e4ac34e..5decdb7dee 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h
@@ -128,6 +128,7 @@ public:
[[nodiscard]] bool parse_date_time();
[[nodiscard]] bool parse_calendar_time();
[[nodiscard]] bool parse_calendar_date_time();
+ [[nodiscard]] bool parse_calendar_date_time_time_required();
[[nodiscard]] bool parse_duration_whole_seconds();
[[nodiscard]] bool parse_duration_seconds_fraction();
[[nodiscard]] bool parse_duration_seconds_part();