1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:37:35 +00:00

LibJS: Make yy{/,-}mm{/,-}dd hh:mm test timezone independent

Otherwise this will fail in non UTC timezones.
This commit is contained in:
Hendiadyoin1 2023-03-23 16:35:45 +01:00 committed by Tim Flynn
parent 6d49eab8a6
commit b76d3f287f

View file

@ -86,7 +86,17 @@ test("mm/dd/yy hh:mm timezone-offset extension", () => {
});
test("yy{/,-}mm{/,-}dd hh:mm extension", () => {
function expectStringToGiveDate(input, fullYear, month, dayInMonth, hours, minutes) {
// Since the timezone is not specified we just say it has to equal the date parts.
const date = new Date(Date.parse(input));
expect(date.getFullYear()).toBe(fullYear);
expect(date.getMonth() + 1).toBe(month);
expect(date.getDate()).toBe(dayInMonth);
expect(date.getHours()).toBe(hours);
expect(date.getMinutes()).toBe(minutes);
}
// Example from a UK news website.
expect(Date.parse("2014/11/14 13:05")).toBe(1415970300000);
expect(Date.parse("2014-11-14 13:05")).toBe(1415970300000);
expectStringToGiveDate("2014/11/14 13:05", 2014, 11, 14, 13, 5);
expectStringToGiveDate("2014-11-14 13:05", 2014, 11, 14, 13, 5);
});