| 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 |
// Make sure all 12 months work |
| 8 |
"Jan 01 2000": "2000-01-01T00:00:00", |
| 9 |
"Feb 01 2000": "2000-02-01T00:00:00", |
| 10 |
"Mar 01 2000": "2000-03-01T00:00:00", |
| 11 |
"Apr 01 2000": "2000-04-01T00:00:00", |
| 12 |
"May 01 2000": "2000-05-01T00:00:00", |
| 13 |
"Jun 01 2000": "2000-06-01T00:00:00", |
| 14 |
"Jul 01 2000": "2000-07-01T00:00:00", |
| 15 |
"Aug 01 2000": "2000-08-01T00:00:00", |
| 16 |
"Sep 01 2000": "2000-09-01T00:00:00", |
| 17 |
"Oct 01 2000": "2000-10-01T00:00:00", |
| 18 |
"Nov 01 2000": "2000-11-01T00:00:00", |
| 19 |
"Dec 01 2000": "2000-12-01T00:00:00", |
| 20 |
|
| 21 |
// Anything after the 3rd character should be ignored |
| 22 |
"Janfoo 01 2000": "2000-01-01T00:00:00", |
| 23 |
"Febfoo 01 2000": "2000-02-01T00:00:00", |
| 24 |
"Marfoo 01 2000": "2000-03-01T00:00:00", |
| 25 |
"Aprfoo 01 2000": "2000-04-01T00:00:00", |
| 26 |
"Mayfoo 01 2000": "2000-05-01T00:00:00", |
| 27 |
"Junfoo 01 2000": "2000-06-01T00:00:00", |
| 28 |
"Julfoo 01 2000": "2000-07-01T00:00:00", |
| 29 |
"Augfoo 01 2000": "2000-08-01T00:00:00", |
| 30 |
"Sepfoo 01 2000": "2000-09-01T00:00:00", |
| 31 |
"Octfoo 01 2000": "2000-10-01T00:00:00", |
| 32 |
"Novfoo 01 2000": "2000-11-01T00:00:00", |
| 33 |
"Decfoo 01 2000": "2000-12-01T00:00:00", |
| 34 |
|
| 35 |
// Check different formats |
| 36 |
"Janfoo-01-2000": "2000-01-01T00:00:00", |
| 37 |
"01-Janfoo-2000": "2000-01-01T00:00:00", |
| 38 |
"01 Janfoo 2000": "2000-01-01T00:00:00", |
| 39 |
}; |
| 40 |
const rejected = [ |
| 41 |
"Foo 01 2000", |
| 42 |
|
| 43 |
"Ja 01 2000", |
| 44 |
"Fe 01 2000", |
| 45 |
"Ma 01 2000", |
| 46 |
"Ap 01 2000", |
| 47 |
"Ma 01 2000", |
| 48 |
"Ju 01 2000", |
| 49 |
"Au 01 2000", |
| 50 |
"Se 01 2000", |
| 51 |
"Oc 01 2000", |
| 52 |
"No 01 2000", |
| 53 |
"De 01 2000", |
| 54 |
|
| 55 |
"Jax 01 2000", |
| 56 |
"Fex 01 2000", |
| 57 |
"Max 01 2000", |
| 58 |
"Apx 01 2000", |
| 59 |
"Max 01 2000", |
| 60 |
"Jux 01 2000", |
| 61 |
"Aux 01 2000", |
| 62 |
"Sex 01 2000", |
| 63 |
"Ocx 01 2000", |
| 64 |
"Nox 01 2000", |
| 65 |
"Dex 01 2000", |
| 66 |
]; |
| 67 |
|
| 68 |
for (const [test, expected] of Object.entries(accepted)) { |
| 69 |
const testDate = new Date(test); |
| 70 |
const expectedDate = new Date(expected); |
| 71 |
|
| 72 |
assertEq( |
| 73 |
false, isNaN(testDate), |
| 74 |
`${test} should be accepted.` |
| 75 |
); |
| 76 |
|
| 77 |
assertEq( |
| 78 |
testDate.getTime(), expectedDate.getTime(), |
| 79 |
`"${test}" should be ${expectedDate} (got ${testDate}).` |
| 80 |
); |
| 81 |
} |
| 82 |
|
| 83 |
for (const reject of rejected) { |
| 84 |
assertEq( |
| 85 |
true, isNaN(new Date(reject)), |
| 86 |
`"${reject}" should be rejected.` |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
if (typeof reportCompare === "function") |
| 91 |
reportCompare(true, true); |