summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-07-30 11:00:08 +0200
committerLinus Groh <mail@linusgroh.de>2022-07-30 10:50:50 +0100
commit6850f258408f651f0ca4684dca0c5fe68aca0a0d (patch)
tree6f3a32314580b070f267a7cd75fff9fb3ba01cd9 /Userland/Libraries/LibJS/Runtime
parent41791146fd146e967dad6289a5c496c7ca106e0a (diff)
downloadserenity-6850f258408f651f0ca4684dca0c5fe68aca0a0d.zip
LibJS: Support IANA legacy names in the Temporal ISO 8601 grammar
This is a normative change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/2419680
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp26
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h1
2 files changed, 27 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp
index eefb0b5bc6..f6f1bc6fe9 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp
@@ -895,12 +895,37 @@ bool ISO8601Parser::parse_time_zone_iana_name_tail()
return true;
}
+// https://tc39.es/proposal-temporal/#prod-TimeZoneIANALegacyName
+bool ISO8601Parser::parse_time_zone_iana_legacy_name()
+{
+ // TimeZoneIANALegacyName :
+ // Etc/GMT0
+ // GMT0
+ // GMT-0
+ // GMT+0
+ // EST5EDT
+ // CST6CDT
+ // MST7MDT
+ // PST8PDT
+ return m_state.lexer.consume_specific("Etc/GMT0"sv)
+ || m_state.lexer.consume_specific("GMT0"sv)
+ || m_state.lexer.consume_specific("GMT-0"sv)
+ || m_state.lexer.consume_specific("GMT+0"sv)
+ || m_state.lexer.consume_specific("EST5EDT"sv)
+ || m_state.lexer.consume_specific("CST6CDT"sv)
+ || m_state.lexer.consume_specific("MST7MDT"sv)
+ || m_state.lexer.consume_specific("PST8PDT"sv);
+}
+
// https://tc39.es/proposal-temporal/#prod-TimeZoneIANAName
bool ISO8601Parser::parse_time_zone_iana_name()
{
// TimeZoneIANAName :
// Etc/GMT ASCIISign UnpaddedHour
// TimeZoneIANANameTail but not Etc/GMT ASCIISign UnpaddedHour
+ // TimeZoneIANALegacyName
+ // NOTE: Reverse order here because `TimeZoneIANANameTail` can be a subset of `TimeZoneIANALegacyName`,
+ // so we'd not attempt to parse that but may not exhaust the input string.
auto parse_etc_gmt_with_offset = [this] {
StateTransaction transaction { *this };
if (!m_state.lexer.consume_specific("Etc/GMT"sv))
@@ -913,6 +938,7 @@ bool ISO8601Parser::parse_time_zone_iana_name()
return true;
};
return parse_etc_gmt_with_offset()
+ || parse_time_zone_iana_legacy_name()
|| parse_time_zone_iana_name_tail();
}
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h
index 4694053ec4..cd9cd142ce 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.h
@@ -136,6 +136,7 @@ public:
[[nodiscard]] bool parse_tz_char();
[[nodiscard]] bool parse_time_zone_iana_component();
[[nodiscard]] bool parse_time_zone_iana_name_tail();
+ [[nodiscard]] bool parse_time_zone_iana_legacy_name();
[[nodiscard]] bool parse_time_zone_iana_name();
[[nodiscard]] bool parse_time_zone_identifier();
[[nodiscard]] bool parse_time_zone_bracketed_annotation();