LibJS: Support date strings of the form "Wed Apr 17 2019 23:08:53""

Seen on https://www.skaping.com/valloire/galibier.
This commit is contained in:
Timothy Flynn 2024-10-14 20:42:42 -04:00 committed by Andreas Kling
parent a3157c8c69
commit c0102aa818
Notes: github-actions[bot] 2024-10-15 06:26:24 +00:00
2 changed files with 3 additions and 1 deletions

View file

@ -181,11 +181,12 @@ static double parse_date_string(VM& vm, ByteString const& date_string)
"%Y-%m-%e%t%T"sv, // "2024-01-15 00:00:01"
"%a%t%b%t%e%t%Y%t%T%t%Z"sv, // "Tue Nov 07 2023 10:05:55 UTC"
"%a%t%b%t%e%t%T%t%Y"sv, // "Wed Apr 17 23:08:53 2019"
"%a%t%b%t%e%t%Y%t%T"sv, // "Wed Apr 17 2019 23:08:53"
"%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"
"%d%t%B%t%Y"sv // "01 February 2013"
"%d%t%B%t%Y"sv, // "01 February 2013"
};
for (auto const& format : extra_formats) {

View file

@ -31,6 +31,7 @@ test("basic functionality", () => {
expect(Date.parse("2024-01-15 00:00:01")).toBe(1705298401000);
expect(Date.parse("Tue Nov 07 2023 10:05:55 UTC")).toBe(1699351555000);
expect(Date.parse("Wed Apr 17 23:08:53 2019")).toBe(1555560533000);
expect(Date.parse("Wed Apr 17 2019 23:08:53")).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);