LibJS: Display example Date strings inline with their format strings

The current comment style feels a bit awkward to read.
This commit is contained in:
Timothy Flynn 2023-11-01 15:38:50 -04:00 committed by Andreas Kling
parent 99233776e6
commit 9d3f942d43

View file

@ -148,15 +148,6 @@ static double parse_simplified_iso8601(DeprecatedString const& iso_8601)
return time_clip(time_ms);
}
static constexpr AK::Array<StringView, 6> 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())