OLD | NEW |
---|---|
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 // Allow missing time. | 198 // Allow missing time. |
199 'Sat, 01-Jan-2000 PST']; | 199 'Sat, 01-Jan-2000 PST']; |
200 | 200 |
201 // PDT = UT minus 7 hours. | 201 // PDT = UT minus 7 hours. |
202 var testCasesPDT = [ | 202 var testCasesPDT = [ |
203 'Sat, 01-Jan-2000 01:00:00 PDT', | 203 'Sat, 01-Jan-2000 01:00:00 PDT', |
204 'Sat, 01 Jan 2000 01:00:00 PDT', | 204 'Sat, 01 Jan 2000 01:00:00 PDT', |
205 'Saturday, 01-Jan-00 01:00:00 PDT', | 205 'Saturday, 01-Jan-00 01:00:00 PDT', |
206 '01 Jan 00 01:00 -0700']; | 206 '01 Jan 00 01:00 -0700']; |
207 | 207 |
208 | |
209 // Local time cases. | 208 // Local time cases. |
210 var testCasesLocalTime = [ | 209 var testCasesLocalTime = [ |
211 // Allow timezone ommision. | 210 // Allow timezone ommision. |
212 'Sat, 01-Jan-2000 08:00:00', | 211 'Sat, 01-Jan-2000 08:00:00', |
213 'Sat, 01 Jan 2000 08:00:00', | 212 'Sat, 01 Jan 2000 08:00:00', |
214 'Jan 01 2000 08:00:00', | 213 'Jan 01 2000 08:00:00', |
215 'Jan 01 08:00:00 2000', | 214 'Jan 01 08:00:00 2000', |
216 'Saturday, 01-Jan-00 08:00:00', | 215 'Saturday, 01-Jan-00 08:00:00', |
217 '01 Jan 00 08:00']; | 216 '01 Jan 00 08:00']; |
218 | 217 |
219 | 218 |
220 // Misc. test cases that result in a different time value. | 219 // Misc. test cases that result in a different time value. |
221 var testCasesMisc = [ | 220 var testCasesMisc = [ |
222 // Special handling for years in the [0, 100) range. | 221 // Special handling for years in the [0, 100) range. |
223 ['Sat, 01 Jan 0 08:00:00 UT', 946713600000], // year 2000 | 222 ['Sat, 01 Jan 0 08:00:00 UT', 946713600000], // year 2000 |
224 ['Sat, 01 Jan 49 08:00:00 UT', 2493100800000], // year 2049 | 223 ['Sat, 01 Jan 49 08:00:00 UT', 2493100800000], // year 2049 |
225 ['Sat, 01 Jan 50 08:00:00 UT', -631123200000], // year 1950 | 224 ['Sat, 01 Jan 50 08:00:00 UT', -631123200000], // year 1950 |
226 ['Sat, 01 Jan 99 08:00:00 UT', 915177600000], // year 1999 | 225 ['Sat, 01 Jan 99 08:00:00 UT', 915177600000], // year 1999 |
227 ['Sat, 01 Jan 100 08:00:00 UT', -59011430400000], // year 100 | 226 ['Sat, 01 Jan 100 08:00:00 UT', -59011430400000], // year 100 |
228 // Test PM after time. | 227 // Test PM after time. |
229 ['Sat, 01-Jan-2000 08:00 PM UT', 946756800000], | 228 ['Sat, 01-Jan-2000 08:00 PM UT', 946756800000], |
230 ['Sat, 01 Jan 2000 08:00 PM UT', 946756800000], | 229 ['Sat, 01 Jan 2000 08:00 PM UT', 946756800000], |
231 ['Jan 01 2000 08:00 PM UT', 946756800000], | 230 ['Jan 01 2000 08:00 PM UT', 946756800000], |
232 ['Jan 01 08:00 PM UT 2000', 946756800000], | 231 ['Jan 01 08:00 PM UT 2000', 946756800000], |
233 ['Saturday, 01-Jan-00 08:00 PM UT', 946756800000], | 232 ['Saturday, 01-Jan-00 08:00 PM UT', 946756800000], |
234 ['01 Jan 00 08:00 PM +0000', 946756800000]]; | 233 ['01 Jan 00 08:00 PM +0000', 946756800000]]; |
235 | 234 |
235 // Test different version of the ES5 date time string format | |
Mads Ager (chromium)
2010/04/29 13:24:01
End comments with period.
| |
236 var testCasesES5Misc = [ | |
237 ['2000-01-01T08:00:00.000Z', 946713600000], | |
238 ['2000-01-01T08:00:00Z', 946713600000], | |
239 ['2000-01-01T08:00Z', 946713600000], | |
240 ['2000-01T08:00:00.000Z', 946713600000], | |
241 ['2000T08:00:00.000Z', 946713600000], | |
242 ['2000T08:00Z', 946713600000], | |
243 ['2000-01T00:00:00.000-08:00', 946713600000], | |
244 ['2000-01T08:00:00.001Z', 946713600001], | |
245 ['2000-01T08:00:00.099Z', 946713600099], | |
246 ['2000-01T08:00:00.999Z', 946713600999], | |
247 ['2000-01T00:00:00.001-08:00', 946713600001]]; | |
248 | |
249 var testCasesES5MiscNegative = [ | |
250 '2000-01-01TZ', | |
251 '2000-01-01T60Z', | |
252 '2000-01-01T60:60Z', | |
253 '2000-01-0108:00Z', | |
254 '2000-01-01T08Z']; | |
255 | |
236 | 256 |
237 // Run all the tests. | 257 // Run all the tests. |
238 testCasesUT.forEach(testDateParse); | 258 testCasesUT.forEach(testDateParse); |
239 testCasesGMT.forEach(testDateParse); | 259 testCasesGMT.forEach(testDateParse); |
240 testCasesEST.forEach(testDateParse); | 260 testCasesEST.forEach(testDateParse); |
241 testCasesEDT.forEach(testDateParse); | 261 testCasesEDT.forEach(testDateParse); |
242 testCasesCST.forEach(testDateParse); | 262 testCasesCST.forEach(testDateParse); |
243 testCasesCDT.forEach(testDateParse); | 263 testCasesCDT.forEach(testDateParse); |
244 testCasesMST.forEach(testDateParse); | 264 testCasesMST.forEach(testDateParse); |
245 testCasesMDT.forEach(testDateParse); | 265 testCasesMDT.forEach(testDateParse); |
246 testCasesPST.forEach(testDateParse); | 266 testCasesPST.forEach(testDateParse); |
247 testCasesPDT.forEach(testDateParse); | 267 testCasesPDT.forEach(testDateParse); |
248 testCasesLocalTime.forEach(testDateParseLocalTime); | 268 testCasesLocalTime.forEach(testDateParseLocalTime); |
249 testCasesMisc.forEach(testDateParseMisc); | 269 testCasesMisc.forEach(testDateParseMisc); |
250 | 270 |
271 // ES5 date time string format compliance | |
Mads Ager (chromium)
2010/04/29 13:24:01
Ditto.
| |
272 testCasesES5Misc.forEach(testDateParseMisc); | |
273 testCasesES5MiscNegative.forEach(function (s) { | |
274 assertTrue(isNaN(Date.parse(s)), s + " is not NaN."); | |
275 }); | |
276 | |
251 | 277 |
252 // Test that we can parse our own date format. | 278 // Test that we can parse our own date format. |
253 // (Dates from 1970 to ~2070 with 150h steps.) | 279 // (Dates from 1970 to ~2070 with 150h steps.) |
254 for (var i = 0; i < 24 * 365 * 100; i += 150) { | 280 for (var i = 0; i < 24 * 365 * 100; i += 150) { |
255 var ms = i * (3600 * 1000); | 281 var ms = i * (3600 * 1000); |
256 var s = (new Date(ms)).toString(); | 282 var s = (new Date(ms)).toString(); |
257 assertEquals(ms, Date.parse(s), "parse own: " + s); | 283 assertEquals(ms, Date.parse(s), "parse own: " + s); |
258 } | 284 } |
259 | 285 |
260 // Negative tests. | 286 // Negative tests. |
261 var testCasesNegative = [ | 287 var testCasesNegative = [ |
262 'May 25 2008 1:30 (PM)) UTC', | 288 'May 25 2008 1:30 (PM)) UTC', |
263 'May 25 2008 1:30( )AM (PM)', | 289 'May 25 2008 1:30( )AM (PM)', |
264 'May 25 2008 AAA (GMT)']; | 290 'May 25 2008 AAA (GMT)']; |
265 | 291 |
266 testCasesNegative.forEach(function (s) { | 292 testCasesNegative.forEach(function (s) { |
267 assertTrue(isNaN(Date.parse(s)), s + " is not NaN."); | 293 assertTrue(isNaN(Date.parse(s)), s + " is not NaN."); |
268 }); | 294 }); |
OLD | NEW |