From 9d3f942d43293eec2ba6b2b59b63233013e54b49 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 1 Nov 2023 15:38:50 -0400 Subject: [PATCH] LibJS: Display example Date strings inline with their format strings The current comment style feels a bit awkward to read. --- .../LibJS/Runtime/DateConstructor.cpp | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp index 180ef464a2..ce37a970d8 100644 --- a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp @@ -148,15 +148,6 @@ static double parse_simplified_iso8601(DeprecatedString const& iso_8601) return time_clip(time_ms); } -static constexpr AK::Array extra_formats = { - "%a %b %e %T %z %Y"sv, - "%m/%e/%Y"sv, - "%m/%e/%Y %R %z"sv, - "%Y/%m/%e %R"sv, - "%Y-%m-%e %R"sv, - "%B %e, %Y %T"sv, -}; - static double parse_date_string(DeprecatedString const& date_string) { auto value = parse_simplified_iso8601(date_string); @@ -164,14 +155,18 @@ static double parse_date_string(DeprecatedString const& date_string) return value; // Date.parse() is allowed to accept an arbitrary number of implementation-defined formats. - // Parse formats of this type: "Wed Apr 17 23:08:53 +0000 2019" - // And: "4/17/2019" - // And: "12/05/2022 10:00 -0800" - // And: "2014/11/14 13:05" or "2014-11-14 13:05" - // And: "June 5, 2023 17:00:00" // FIXME: Exactly what timezone and which additional formats we should support is unclear. // Both Chrome and Firefox seem to support "4/17/2019 11:08 PM +0000" with most parts // being optional, however this is not clearly documented anywhere. + static constexpr auto extra_formats = AK::Array { + "%a %b %e %T %z %Y"sv, // "Wed Apr 17 23:08:53 +0000 2019" + "%m/%e/%Y"sv, // "4/17/2019" + "%m/%e/%Y %R %z"sv, // "12/05/2022 10:00 -0800" + "%Y/%m/%e %R"sv, // "2014/11/14 13:05" + "%Y-%m-%e %R"sv, // "2014-11-14 13:05" + "%B %e, %Y %T"sv, // "June 5, 2023 17:00:00" + }; + for (auto const& format : extra_formats) { auto maybe_datetime = Core::DateTime::parse(format, date_string); if (maybe_datetime.has_value())