1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
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"],
// MMM-dd-yyyy
["Apr-24-2023", "2023-04-24T00:00:00"],
["apr-24-2023", "2023-04-24T00:00:00"],
["April-24-2023", "2023-04-24T00:00:00"],
["APRIL-24-2023", "2023-04-24T00:00:00"],
["Apr-24-2033", "2033-04-24T00:00:00"],
["Apr-24-0023", "0023-04-24T00:00:00"],
// MMM-dd-yy
["Apr-24-23", "2023-04-24T00:00:00"],
["Apr-24-33", "2033-04-24T00:00:00"],
// MMM-dd-yyy
["Apr-24-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,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-2023GMT", "2023-04-24T00:00:00Z"],
["24-Apr-2023GMT-04", "2023-04-24T00:00:00-04:00"],
["24-Apr-2023GMT-04:30", "2023-04-24T00:00:00-04:30"],
["24-Apr-2023GMT+04", "2023-04-24T00:00:00+04:00"],
["24-Apr-2023GMT+04:30", "2023-04-24T00:00:00+04:30"],
["24-Apr-2023,GMT", "2023-04-24T00:00:00Z"],
["24-Apr-2023/GMT", "2023-04-24T00:00:00Z"],
["24-Apr-2023/12:34:56", "2023-04-24T12:34:56"],
["Apr-24-2023 12:34:56", "2023-04-24T12:34:56"],
["Apr-24-2023 12:34:56 GMT", "2023-04-24T12:34:56Z"],
["Apr-24-2023 12:34:56 +04", "2023-04-24T12:34:56+04:00"],
["Apr-24-2023 12:34:56 +04:30", "2023-04-24T12:34:56+04:30"],
// ==== non dd-MMM-yyyy. Uses fallback path ====
// 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"],
// year w/ 5 or 6 digits
["24-Apr-10000", "+010000-04-24T00:00:00"],
["24-Apr-10000 10:00", "+010000-04-24T10:00:00"],
["24-Apr-275760", "+275760-04-24T00:00:00"],
// Delimiter other than space after prefix
["24-Apr-2312.10:13:14", "2312-04-24T10:13:14"],
["24-Apr-2312,10:13:14", "2312-04-24T10:13:14"],
["24-Apr-2312-10:13:14", "2312-04-24T10:13:14"],
["24-Apr-2312-04:30", "2312-04-24T04:30:00"],
["24-Apr-2312/10:13:14", "2312-04-24T10:13:14"],
["24-Apr-2312()10:13:14", "2312-04-24T10:13:14"],
// Open paren only comments out the time
["24-Apr-2312(10:13:14", "2312-04-24T00:00:00"],
// mday being 3+ digits, while year being 2-3 digits.
["024-Apr-23", "2023-04-24T00:00:00"],
["024-Apr-023", "2023-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",
// Duplicate date.
"2012-Apr-08 12/12/12",
// > TimeClip limit
"13-Sep-275760 00:00:01 GMT",
// Rejected delimiters after prefix
"24-Apr-2312T10:13:14",
"24-Apr-2312:10:13:14",
"24-Apr-2312^10:13:14",
"24-Apr-2312|10:13:14",
"24-Apr-2312~10:13:14",
"24-Apr-2312+10:13:14",
"24-Apr-2312=10:13:14",
"24-Apr-2312?10:13:14",
// Late weekday
"24-Apr-2023 Mon 12:34:56",
"24-Apr-2023,Mon 12:34:56",
];
for (const testString of invalidTests) {
assertEq(Number.isNaN(new Date(testString).getTime()), true, testString);
}
if (typeof reportCompare === "function")
reportCompare(true, true);
|