From 179641a297ab0b4bafcce3a6361be2c4ed0c51ea Mon Sep 17 00:00:00 2001 From: rmg-x Date: Fri, 20 Sep 2024 18:23:42 -0500 Subject: [PATCH] LibJS: Add extra date format "d B Y" This allows date strings like "01 February 2013" to be parsed. auth0.com also loads now because of this :^) Add test for date parsing --- Userland/Libraries/LibJS/Runtime/DateConstructor.cpp | 3 ++- Userland/Libraries/LibJS/Tests/builtins/Date/Date.parse.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp index 42dabf0499d..53c1e1a7c9a 100644 --- a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp @@ -181,7 +181,8 @@ static double parse_date_string(VM& vm, ByteString const& date_string) "%Y-%m-%eT%T%X%z"sv, // "2024-01-26T22:10:11.306+0000" "%m/%e/%Y,%t%T%t%p"sv, // "1/27/2024, 9:28:30 AM" "%Y-%m-%e"sv, // "2024-1-15" - "%Y-%m-%e%t%T%tGMT%z"sv // "2024-07-05 00:00:00 GMT-0800" + "%Y-%m-%e%t%T%tGMT%z"sv, // "2024-07-05 00:00:00 GMT-0800" + "%d%t%B%t%Y"sv // "01 February 2013" }; for (auto const& format : extra_formats) { diff --git a/Userland/Libraries/LibJS/Tests/builtins/Date/Date.parse.js b/Userland/Libraries/LibJS/Tests/builtins/Date/Date.parse.js index 0a2fa7bd620..6a043889c9e 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Date/Date.parse.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Date/Date.parse.js @@ -33,6 +33,7 @@ test("basic functionality", () => { expect(Date.parse("Wed Apr 17 23:08:53 2019")).toBe(1555560533000); expect(Date.parse("2024-01-26T22:10:11.306+0000")).toBe(1706307011000); // FIXME: support sub-second precision expect(Date.parse("1/27/2024, 9:28:30 AM")).toBe(1706369310000); + expect(Date.parse("01 February 2013")).toBe(1359698400000); // FIXME: Create a scoped time zone helper when bytecode supports the `using` declaration. setTimeZone(originalTimeZone);