Sfoglia il codice sorgente

LibJS: Parse dates like "Wed Nov 20 2024"

rmg-x 7 mesi fa
parent
commit
74b27d620d

+ 1 - 0
Libraries/LibJS/Runtime/DateConstructor.cpp

@@ -192,6 +192,7 @@ static double parse_date_string(VM& vm, ByteString const& date_string)
         "%d%t%b%t%Y%t%R"sv,                    // "01 Jan 2000 08:00"
         "%d%t%b%t%Y%t%R"sv,                    // "01 Jan 2000 08:00"
         "%A,%t%B%t%e,%t%Y,%t%R%t%Z"sv,         // "Tuesday, October 29, 2024, 18:00 UTC"
         "%A,%t%B%t%e,%t%Y,%t%R%t%Z"sv,         // "Tuesday, October 29, 2024, 18:00 UTC"
         "%B%t%d%t%Y%t%T%t%z"sv,                // "November 19 2024 00:00:00 +0900"
         "%B%t%d%t%Y%t%T%t%z"sv,                // "November 19 2024 00:00:00 +0900"
+        "%a%t%b%t%e%t%Y"sv                     // "Wed Nov 20 2024"
     };
     };
 
 
     for (auto const& format : extra_formats) {
     for (auto const& format : extra_formats) {

+ 1 - 0
Libraries/LibJS/Tests/builtins/Date/Date.parse.js

@@ -41,6 +41,7 @@ test("basic functionality", () => {
     expect(Date.parse("01 February 2013")).toBe(1359698400000);
     expect(Date.parse("01 February 2013")).toBe(1359698400000);
     expect(Date.parse("Tuesday, October 29, 2024, 18:00 UTC")).toBe(1730224800000);
     expect(Date.parse("Tuesday, October 29, 2024, 18:00 UTC")).toBe(1730224800000);
     expect(Date.parse("November 19 2024 00:00:00 +0900")).toBe(1731942000000);
     expect(Date.parse("November 19 2024 00:00:00 +0900")).toBe(1731942000000);
+    expect(Date.parse("Wed Nov 20 2024")).toBe(1732082400000);
 
 
     // FIXME: Create a scoped time zone helper when bytecode supports the `using` declaration.
     // FIXME: Create a scoped time zone helper when bytecode supports the `using` declaration.
     setTimeZone(originalTimeZone);
     setTimeZone(originalTimeZone);