diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Date/dashed-date.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Date/dashed-date.js')
-rw-r--r-- | js/src/tests/non262/Date/dashed-date.js | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/js/src/tests/non262/Date/dashed-date.js b/js/src/tests/non262/Date/dashed-date.js new file mode 100644 index 0000000000..a1babf991e --- /dev/null +++ b/js/src/tests/non262/Date/dashed-date.js @@ -0,0 +1,118 @@ +const tests = [ + // ==== Date only ==== + + // dd-MMM-yyyy + ["24-Apr-2023", "2023-04-24T00:00:00"], + ["24-apr-2023", "2023-04-24T00:00:00"], + ["24-April-2023", "2023-04-24T00:00:00"], + ["24-APRIL-2023", "2023-04-24T00:00:00"], + ["24-Apr-2033", "2033-04-24T00:00:00"], + + ["24-Apr-0023", "0023-04-24T00:00:00"], + + // dd-MMM-yy + ["24-Apr-23", "2023-04-24T00:00:00"], + ["24-Apr-33", "2033-04-24T00:00:00"], + + // dd-MMM-yyy + ["24-Apr-023", "2023-04-24T00:00:00"], + + // yyyy-MM-dd + ["2023-Apr-24", "2023-04-24T00:00:00"], + ["2033-Apr-24", "2033-04-24T00:00:00"], + + // yy-MM-dd + ["33-Apr-24", "2033-04-24T00:00:00"], + + // yyy-MM-dd + ["033-Apr-24", "2033-04-24T00:00:00"], + + // ==== Date followed by hour and TZ ==== + + ["24-Apr-2023 12:34:56", "2023-04-24T12:34:56"], + ["24-Apr-2023 Mon 12:34:56", "2023-04-24T12:34:56"], + ["24-Apr-2023 (Mon) 12:34:56", "2023-04-24T12:34:56"], + ["24-Apr-2023(Mon)12:34:56", "2023-04-24T12:34:56"], + + ["24-Apr-2023,12:34:56", "2023-04-24T12:34:56"], + ["24-Apr-2023,Mon 12:34:56", "2023-04-24T12:34:56"], + + ["24-Apr-2023 12:34:56 GMT", "2023-04-24T12:34:56Z"], + ["24-Apr-2023 12:34:56 +04", "2023-04-24T12:34:56+04:00"], + ["24-Apr-2023 12:34:56 +04:30", "2023-04-24T12:34:56+04:30"], + ["24-Apr-2023 12:34:56 -04", "2023-04-24T12:34:56-04:00"], + ["24-Apr-2023 12:34:56 -04:30", "2023-04-24T12:34:56-04:30"], + + ["24-Apr-2023 GMT", "2023-04-24T00:00:00Z"], + ["24-Apr-2023 +04", "2023-04-24T00:00:00+04:00"], + ["24-Apr-2023 +04:30", "2023-04-24T00:00:00+04:30"], + ["24-Apr-2023 -04", "2023-04-24T00:00:00-04:00"], + ["24-Apr-2023 -04:30", "2023-04-24T00:00:00-04:30"], + + ["24-Apr-2023GMT", "2023-04-24T00:00:00Z"], + ["24-Apr-2023+04", "2023-04-24T00:00:00+04:00"], + ["24-Apr-2023+04:30", "2023-04-24T00:00:00+04:30"], + ["24-Apr-2023-04", "2023-04-24T00:00:00-04:00"], + ["24-Apr-2023-04:30", "2023-04-24T00:00:00-04:30"], + + ["24-Apr-2023,GMT", "2023-04-24T00:00:00Z"], + ["24-Apr-2023,+04", "2023-04-24T00:00:00+04:00"], + ["24-Apr-2023,+04:30", "2023-04-24T00:00:00+04:30"], + ["24-Apr-2023,-04", "2023-04-24T00:00:00-04:00"], + ["24-Apr-2023,-04:30", "2023-04-24T00:00:00-04:30"], + + ["24-Apr-2023/12:34:56", "2023-04-24T12:34:56"], + ["24-Apr-2023/GMT", "2023-04-24T00:00:00Z"], + + // ==== non dd-MMM-yyyy. Uses fallback path ==== + + // Missing space. + ["24-Apr-202312:13:14", "-202312-04-24T13:14:00"], + + // Extra delimiter. + ["24-Apr- 2023", "2023-04-24T00:00:00"], + ["24-Apr -2023", "-002023-04-24T00:00:00"], + ["24- Apr-2023", "-002023-04-24T00:00:00"], + ["24 -Apr-2023", "-002023-04-24T00:00:00"], + + ["24-Apr-/2023", "2023-04-24T00:00:00"], + ["24-Apr/-2023", "-002023-04-24T00:00:00"], + ["24-/Apr-2023", "-002023-04-24T00:00:00"], + ["24/-Apr-2023", "-002023-04-24T00:00:00"], + + ["24-Apr-()2023", "2023-04-24T00:00:00"], + ["24-Apr()-2023", "-002023-04-24T00:00:00"], + ["24-()Apr-2023", "-002023-04-24T00:00:00"], + ["24()-Apr-2023", "-002023-04-24T00:00:00"], + + // mday being 3+ digits + ["024-Apr-2023", "-002023-04-24T00:00:00"], + ["0024-Apr-2023", "-002023-04-24T00:00:00"], +]; + +for (const [testString, isoString] of tests) { + const testDate = new Date(testString); + const isoDate = new Date(isoString); + + assertEq(testDate.getTime(), isoDate.getTime(), + testString); +} + +const invalidTests = [ + // mday being out of range. + "32-01-32", + + // mday being 3+ digits, while year being 2-3 digits. + "024-Apr-22", + "024-Apr-023", + + // Duplicate date. + "2012-Apr-08 12/12/12", +]; + +for (const testString of invalidTests) { + assertEq(Number.isNaN(new Date(testString).getTime()), true, testString); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |