• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15var wrongFormats = ["",
16                    "2",
17                    "20",
18                    "201",
19                    "2015-",
20                    "2015-01-",
21                    "2015-01-01-",
22                    "qwerty",
23                    "2015-01-01T",
24                    "2015-01-01T1:1",
25                    "2015-01-01T01",
26                    "2015-01-01T01",
27                    "2015-01-01T01:01F",
28                    "T2015",
29                    "2015-01-01Z",
30                    "2015-01-01+01:00",
31                    "2015-01-01T00:00+01",
32                    "2015-01-01T00:00+1",
33                    "2015-01-01T00:00-01",
34                    "2015-01-01T00:00.000",
35                    "2015-01-01T00:00:",
36                    "2015-01-01T00:",
37                    "2015-01-01T00:00:00.1",
38                    "2015-01-01T00:00:00.01",
39                    "2015-01-01T24:01:00.000",
40                    "2015-01-01T24:00:01.000",
41                    "2015-01-01T24:00:00.001",
42                    "2015-01-01T00:00+01:00Z",
43                    "2015/01/01",
44                    "2015-01-32",
45                    "2015--1",
46                    "2015-13",
47                    "2015-01--1",
48                    "-215",
49                    "-215-01-01",
50                    "2015-01-00",
51                    "2015-01-01T25:00",
52                    "2015-01-01T00:60",
53                    "2015-01-01T-1:00",
54                    "2015-01-01T00:-1",
55                    "2e+3",
56                    "+2015-01-01",
57                    "-2015-01-01",
58                    "+02015-01-01",
59                    "-02015-01-01",
60                    "002015-01-01",
61                    "+0002015-01-01",
62                    "-0002015-01-01",
63                    "2015-01T00:00:00.000-03X00",
64                    "2015-01-01T00-03:00",
65                    "Fri Jan 01 1 00:00:00 GMT+0000",
66                    "Fri Jan 01 11 00:00:00 GMT+0000",
67                    "Fri Jan 01 111 00:00:00 GMT+0000",
68                    "Fri Jan 01 1234567 00:00:00 GMT+0000",
69                    "Fri Jan 01 +1000 00:00:00 GMT+0000",
70                    "Fri Jan 01 -1 00:00:00 GMT+0000",
71                    "Fri Jan 01 -11 00:00:00 GMT+0000",
72                    "Fri Jan 01 -111 00:00:00 GMT+0000",
73                    "Fri Jan 01 -1234567 00:00:00 GMT+0000",
74                    "Thu Apr 10 1997"];
75
76for (i in wrongFormats) {
77  var d = Date.parse(wrongFormats[i]);
78  assert (isNaN(d));
79}
80
81var d;
82
83d = Date.parse(undefined);
84assert (isNaN(d));
85
86d = Date.parse({});
87assert (isNaN(d));
88
89d = Date.parse(2000 + 15);
90assert (d == 1420070400000);
91
92d = Date.parse("2015");
93assert (d == 1420070400000);
94
95d = Date.parse("2015-01");
96assert (d == 1420070400000);
97
98d = Date.parse("2015-01-01");
99assert (d == 1420070400000);
100
101d = Date.parse("2015-01T00:00");
102assert (d == 1420070400000);
103
104d = Date.parse("2015-01T00:00:00");
105assert (d == 1420070400000);
106
107d = Date.parse("2015-01T00:00:00.000");
108assert (d == 1420070400000);
109
110d = Date.parse("2015-01T24:00:00.000");
111assert (d == 1420156800000);
112
113d = Date.parse("2015-01T00:00:00.000+03:00");
114assert (d == 1420059600000);
115
116d = Date.parse("2015-01T00:00:00.000-03:00");
117assert (d == 1420081200000);
118
119d = Date.parse("2015-07-03T14:35:43.123+01:30");
120assert (d == 1435928743123);
121
122assert (Date.parse("-271821-04-20T00:00:00.000Z") == -8640000000000000)
123assert (Date.parse("-000001-12-31T23:59:59.999Z") == -62167219200001)
124assert (Date.parse("0000-01-01T00:00:00.000Z") == -62167219200000)
125assert (Date.parse("0009-12-31T23:59:59.999Z") == -61851600000001)
126assert (Date.parse("0010-01-01T00:00:00.000Z") == -61851600000000)
127assert (Date.parse("0099-12-31T23:59:59.999Z") == -59011459200001)
128assert (Date.parse("0100-01-01T00:00:00.000Z") == -59011459200000)
129assert (Date.parse("0999-12-31T23:59:59.999Z") == -30610224000001)
130assert (Date.parse("1000-01-01T00:00:00.000Z") == -30610224000000)
131assert (Date.parse("1969-12-31T23:59:59.999Z") == -1)
132assert (Date.parse("1970-01-01T00:00:00.000Z") == 0)
133assert (Date.parse("1970-01-01T00:00:00.001Z") == 1)
134assert (Date.parse("9999-12-31T23:59:59.999Z") == 253402300799999)
135assert (Date.parse("+010000-01-01T00:00:00.000Z") == 253402300800000)
136assert (Date.parse("+275760-09-13T00:00:00.000Z") == 8640000000000000)
137assert (Date.parse("+275760-09-13T00:00:00.001Z") == 8640000000000001)
138
139// Date.toString() format
140assert (Date.parse("Tue Apr 20 -271821 00:00:00 GMT+0000") == -8640000000000000)
141assert (Date.parse("Fri Dec 31 -0001 23:59:59 GMT+0000") == -62167219201000)
142assert (Date.parse("Sat Jan 01 0000 00:00:00 GMT+0000") == -62167219200000)
143assert (Date.parse("Thu Dec 31 0009 23:59:59 GMT+0000") == -61851600001000)
144assert (Date.parse("Fri Jan 01 0010 00:00:00 GMT+0000") == -61851600000000)
145assert (Date.parse("Thu Dec 31 0099 23:59:59 GMT+0000") == -59011459201000)
146assert (Date.parse("Fri Jan 01 0100 00:00:00 GMT+0000") == -59011459200000)
147assert (Date.parse("Tue Dec 31 0999 23:59:59 GMT+0000") == -30610224001000)
148assert (Date.parse("Wed Jan 01 1000 00:00:00 GMT+0000") == -30610224000000)
149assert (Date.parse("Wed Dec 31 1969 23:59:59 GMT+0000") == -1000)
150assert (Date.parse("Thu Jan 01 1970 00:00:00 GMT+0000") == 0)
151assert (Date.parse("Thu Jan 01 1970 00:00:01 GMT+0000") == 1000)
152assert (Date.parse("Fri Dec 31 9999 23:59:59 GMT+0000") == 253402300799000)
153assert (Date.parse("Sat Jan 01 10000 00:00:00 GMT+0000") == 253402300800000)
154assert (Date.parse("Sat Sep 13 275760 00:00:00 GMT+0000") == 8640000000000000)
155
156// Date.toUTCString() format
157assert (Date.parse("Tue, 20 Apr -271821 00:00:00 GMT") == -8640000000000000)
158assert (Date.parse("Fri, 31 Dec -0001 23:59:59 GMT") == -62167219201000)
159assert (Date.parse("Sat, 01 Jan 0000 00:00:00 GMT") == -62167219200000)
160assert (Date.parse("Thu, 31 Dec 0009 23:59:59 GMT") == -61851600001000)
161assert (Date.parse("Fri, 01 Jan 0010 00:00:00 GMT") == -61851600000000)
162assert (Date.parse("Thu, 31 Dec 0099 23:59:59 GMT") == -59011459201000)
163assert (Date.parse("Fri, 01 Jan 0100 00:00:00 GMT") == -59011459200000)
164assert (Date.parse("Tue, 31 Dec 0999 23:59:59 GMT") == -30610224001000)
165assert (Date.parse("Wed, 01 Jan 1000 00:00:00 GMT") == -30610224000000)
166assert (Date.parse("Wed, 31 Dec 1969 23:59:59 GMT") == -1000)
167assert (Date.parse("Thu, 01 Jan 1970 00:00:00 GMT") == 0)
168assert (Date.parse("Thu, 01 Jan 1970 00:00:01 GMT") == 1000)
169assert (Date.parse("Fri, 31 Dec 9999 23:59:59 GMT") == 253402300799000)
170assert (Date.parse("Sat, 01 Jan 10000 00:00:00 GMT") == 253402300800000)
171assert (Date.parse("Sat, 13 Sep 275760 00:00:00 GMT") == 8640000000000000)
172