| 1 |
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ |
| 2 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 |
|
| 6 |
const accepted = { |
| 7 |
"1995-09-26T00:00:00-0500": [ |
| 8 |
"Sep 26 1995 GMT-0500", |
| 9 |
"Sep 26 1995 00:00:00 GMT-0500", |
| 10 |
"Sep 26 1995 00:00:00 gmt-0500", |
| 11 |
"Sep 26 1995 00:00:00 Z-0500", |
| 12 |
"Sep 26 1995 00:00:00 UT-0500", |
| 13 |
"Sep 26 1995 00:00:00 UTC-0500", |
| 14 |
"Sep 26 1995 00:00:00 -0500", |
| 15 |
"Sep 26 1995 00:00:00 -05", |
| 16 |
"Sep 26 1995 00:00:00-0500", |
| 17 |
"Sep 26 1995 00:00:00-05", |
| 18 |
"Sep 26 1995 00:00 -0500", |
| 19 |
"Sep 26 1995 00:00 -05", |
| 20 |
"Sep 26 1995 00:00-0500", |
| 21 |
"Sep 26 1995 00:00-05", |
| 22 |
], |
| 23 |
|
| 24 |
"1995-09-26T00:00:00+0500": [ |
| 25 |
"Sep 26 1995 GMT+0500", |
| 26 |
"Sep 26 1995 00:00:00 GMT+0500", |
| 27 |
"Sep 26 1995 00:00:00 gmt+0500", |
| 28 |
"Sep 26 1995 00:00:00 Z+0500", |
| 29 |
"Sep 26 1995 00:00:00 UT+0500", |
| 30 |
"Sep 26 1995 00:00:00 UTC+0500", |
| 31 |
"Sep 26 1995 00:00:00 +0500", |
| 32 |
"Sep 26 1995 00:00:00 +05", |
| 33 |
"Sep 26 1995 00:00:00+0500", |
| 34 |
"Sep 26 1995 00:00:00+05", |
| 35 |
"Sep 26 1995 00:00 +0500", |
| 36 |
"Sep 26 1995 00:00 +05", |
| 37 |
"Sep 26 1995 00:00+0500", |
| 38 |
"Sep 26 1995 00:00+05", |
| 39 |
], |
| 40 |
|
| 41 |
"1995-09-26T00:00:00-0430": [ |
| 42 |
"Sep 26 1995 GMT-04:30", |
| 43 |
"Sep 26 1995 00:00:00 GMT-04:30", |
| 44 |
"Sep 26 1995 00:00:00 -04:30", |
| 45 |
"Sep 26 1995 00:00:00-04:30", |
| 46 |
"Sep 26 1995 00:00 -04:30", |
| 47 |
"Sep 26 1995 00:00-04:30", |
| 48 |
], |
| 49 |
|
| 50 |
"1995-09-26T00:00:00+0430": [ |
| 51 |
"Sep 26 1995 GMT+04:30", |
| 52 |
"Sep 26 1995 00:00:00 GMT+04:30", |
| 53 |
"Sep 26 1995 00:00:00 +04:30", |
| 54 |
"Sep 26 1995 00:00:00+04:30", |
| 55 |
"Sep 26 1995 00:00 +04:30", |
| 56 |
"Sep 26 1995 00:00+04:30", |
| 57 |
], |
| 58 |
|
| 59 |
"1995-09-26T04:30:00": [ |
| 60 |
"Sep 26 1995-04:30", |
| 61 |
"1995-09-26-04:30", |
| 62 |
"1995-Sep-26-04:30", |
| 63 |
], |
| 64 |
}; |
| 65 |
const rejected = [ |
| 66 |
"Sep 26 1995 -05", |
| 67 |
"Sep 26 1995-05", |
| 68 |
"Sep 26 1995 -04:30", |
| 69 |
"1995-09-26 -05", |
| 70 |
"1995-09-26 -04:30", |
| 71 |
"1995-09-26-05", |
| 72 |
"1995-Sep-26 -05", |
| 73 |
"1995-Sep-26-05", |
| 74 |
"1995-Sep-26,-05", |
| 75 |
|
| 76 |
"Sep 26 1995 +05", |
| 77 |
"Sep 26 1995 +04:30", |
| 78 |
"Sep 26 1995+05", |
| 79 |
"Sep 26 1995+04:30", |
| 80 |
"1995-09-26 +05", |
| 81 |
"1995-09-26+05", |
| 82 |
"1995-Sep-26 +05", |
| 83 |
"1995-Sep-26+05", |
| 84 |
"1995-Sep-26,+05", |
| 85 |
|
| 86 |
// These cases are allowed by V8 but are parsed as GMT-XXXX no matter the |
| 87 |
// abbreviation (e.g. EST-0500 is parsed as GMT-0500 and not GMT-1000). This |
| 88 |
// is unexpected and so we are explicitly rejecting them. |
| 89 |
"Sep 26 1995 00:00:00 EST-0500", |
| 90 |
"Sep 26 1995 00:00:00 MDT-0500", |
| 91 |
]; |
| 92 |
|
| 93 |
for (const [expected, patterns] of Object.entries(accepted)) { |
| 94 |
for (const test of patterns) { |
| 95 |
const testDate = new Date(test); |
| 96 |
const expectedDate = new Date(expected); |
| 97 |
|
| 98 |
assertEq( |
| 99 |
false, isNaN(testDate), |
| 100 |
`${test} should be accepted.` |
| 101 |
); |
| 102 |
|
| 103 |
assertEq( |
| 104 |
testDate.getTime(), expectedDate.getTime(), |
| 105 |
`"${test}" should be ${expectedDate} (got ${testDate}).` |
| 106 |
); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
for (const reject of rejected) { |
| 111 |
assertEq( |
| 112 |
true, isNaN(new Date(reject)), |
| 113 |
`"${reject}" should be rejected.` |
| 114 |
); |
| 115 |
} |
| 116 |
|
| 117 |
if (typeof reportCompare === "function") |
| 118 |
reportCompare(true, true); |