LibJS: Add "month day, year" support to Date.parse
Used on https://rauchg.com.
This commit is contained in:
parent
10064d0e1a
commit
921a9cef62
Notes:
github-actions[bot]
2024-09-08 16:26:05 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/921a9cef621 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1331
2 changed files with 15 additions and 0 deletions
Userland/Libraries/LibJS
|
@ -168,6 +168,7 @@ static double parse_date_string(ByteString const& date_string)
|
|||
"%m/%e/%Y%t%R%t%z"sv, // "12/05/2022 10:00 -0800"
|
||||
"%Y/%m/%e%t%R"sv, // "2014/11/14 13:05"
|
||||
"%Y-%m-%e%t%R"sv, // "2014-11-14 13:05"
|
||||
"%B%t%e,%t%Y"sv, // "June 5, 2023"
|
||||
"%B%t%e,%t%Y%t%T"sv, // "June 5, 2023 17:00:00"
|
||||
"%b%t%d%t%Y%t%Z"sv, // "Jan 01 1970 GMT"
|
||||
"%a%t%b%t%e%t%T%t%Y%t%z"sv, // "Wed Apr 17 23:08:53 2019 +0000"
|
||||
|
|
|
@ -121,6 +121,20 @@ test("yy{/,-}mm{/,-}dd hh:mm extension", () => {
|
|||
expectStringToGiveDate("2014-11-14 13:05", 2014, 11, 14, 13, 5);
|
||||
});
|
||||
|
||||
test("Month dd, yy extension", () => {
|
||||
function expectStringToGiveDate(input, fullYear, month, dayInMonth) {
|
||||
const date = new Date(Date.parse(input));
|
||||
expect(date.getFullYear()).toBe(fullYear);
|
||||
expect(date.getMonth() + 1).toBe(month);
|
||||
expect(date.getDate()).toBe(dayInMonth);
|
||||
}
|
||||
|
||||
expectStringToGiveDate("May 15, 2023", 2023, 5, 15);
|
||||
expectStringToGiveDate("May 22, 2023", 2023, 5, 22);
|
||||
expectStringToGiveDate("May 30, 2023", 2023, 5, 30);
|
||||
expectStringToGiveDate("June 5, 2023", 2023, 6, 5);
|
||||
});
|
||||
|
||||
test("Month dd, yy hh:mm:ss extension", () => {
|
||||
function expectStringToGiveDate(input, fullYear, month, dayInMonth, hours, minutes, seconds) {
|
||||
// Since the timezone is not specified we just say it has to equal the date parts.
|
||||
|
|
Loading…
Add table
Reference in a new issue