parse-keywords.js (1502B)
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 "Sep 26 1995 UT": "1995-09-26T00:00:00Z", 8 "Sep 26 1995 UTC": "1995-09-26T00:00:00Z", 9 "Sep 26 1995 GMT": "1995-09-26T00:00:00Z", 10 "Sep 26 1995 EST": "1995-09-26T00:00:00-0500", 11 "Sep 26 1995 est": "1995-09-26T00:00:00-0500", 12 "Sep 26 1995 10:00 am": "1995-09-26T10:00:00", 13 "Sep 26 1995 10:00 AM": "1995-09-26T10:00:00", 14 "Sep 26 1995 10:00 pm": "1995-09-26T22:00:00", 15 }; 16 const rejected = [ 17 "Sep 26 1995 G", 18 "Sep 26 1995 GM", 19 "Sep 26 1995 E", 20 "Sep 26 1995 ES", 21 "Sep 26 1995 10:00 a", 22 "Sep 26 1995 10:00 p", 23 "0/zx", 24 25 // Late weekday 26 "Sep 26 Thurs 1995 10:00", 27 "Sep 26 1995 Thurs 10:00", 28 "Sep 26 1995 10:Thurs:00", 29 "Sep 26 1995 10:00 Thurs", 30 ]; 31 32 for (const [test, expected] of Object.entries(accepted)) { 33 const testDate = new Date(test); 34 const expectedDate = new Date(expected); 35 36 assertEq( 37 false, isNaN(testDate), 38 `${test} should be accepted.` 39 ); 40 41 assertEq( 42 testDate.getTime(), expectedDate.getTime(), 43 `"${test}" should be ${expectedDate} (got ${testDate}).` 44 ); 45 } 46 47 for (const reject of rejected) { 48 assertEq( 49 true, isNaN(new Date(reject)), 50 `"${reject}" should be rejected.` 51 ); 52 } 53 54 if (typeof reportCompare === "function") 55 reportCompare(true, true);