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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 d.setTime(Math.pow(-2, 64)); | 196 d.setTime(Math.pow(-2, 64)); |
197 assertTrue(isNaN(d.getTime())); | 197 assertTrue(isNaN(d.getTime())); |
198 | 198 |
199 | 199 |
200 // Test creation with obscure date values. | 200 // Test creation with obscure date values. |
201 assertEquals(8640000000000000, Date.UTC(1970, 0, 1 + 100000001, -24)); | 201 assertEquals(8640000000000000, Date.UTC(1970, 0, 1 + 100000001, -24)); |
202 assertEquals(-8640000000000000, Date.UTC(1970, 0, 1 - 100000001, 24)); | 202 assertEquals(-8640000000000000, Date.UTC(1970, 0, 1 - 100000001, 24)); |
203 | 203 |
204 | 204 |
205 // Parsing ES5 ISO-8601 dates. | 205 // Parsing ES5 ISO-8601 dates. |
206 // When TZ is omitted, it defaults to the local timezone | 206 // When TZ is omitted, it defaults to 'Z' meaning UTC. |
207 | 207 |
208 // Check epoch. | 208 // Check epoch. |
209 assertEquals(0, Date.parse("1970-01-01T00:00:00.000+00:00")); | 209 assertEquals(0, Date.parse("1970-01-01T00:00:00.000+00:00")); |
210 assertEquals(0, Date.parse("1970-01-01T00:00:00.000-00:00")); | 210 assertEquals(0, Date.parse("1970-01-01T00:00:00.000-00:00")); |
211 assertEquals(0, Date.parse("1970-01-01T00:00:00.000Z")); | 211 assertEquals(0, Date.parse("1970-01-01T00:00:00.000Z")); |
212 assertEquals(0, Date.parse("1970-01-01T00:00:00.000Z")); | 212 assertEquals(0, Date.parse("1970-01-01T00:00:00.000")); |
213 assertEquals(0, Date.parse("1970-01-01T00:00:00Z")); | 213 assertEquals(0, Date.parse("1970-01-01T00:00:00")); |
214 assertEquals(0, Date.parse("1970-01-01T00:00Z")); | 214 assertEquals(0, Date.parse("1970-01-01T00:00")); |
215 assertEquals(0, Date.parse("1970-01-01Z")); | 215 assertEquals(0, Date.parse("1970-01-01")); |
216 | 216 |
217 assertEquals(0, Date.parse("1970-01T00:00:00.000+00:00")); | 217 assertEquals(0, Date.parse("1970-01T00:00:00.000+00:00")); |
218 assertEquals(0, Date.parse("1970-01T00:00:00.000-00:00")); | 218 assertEquals(0, Date.parse("1970-01T00:00:00.000-00:00")); |
219 assertEquals(0, Date.parse("1970-01T00:00:00.000Z")); | 219 assertEquals(0, Date.parse("1970-01T00:00:00.000Z")); |
220 assertEquals(0, Date.parse("1970-01T00:00:00.000Z")); | 220 assertEquals(0, Date.parse("1970-01T00:00:00.000")); |
221 assertEquals(0, Date.parse("1970-01T00:00:00Z")); | 221 assertEquals(0, Date.parse("1970-01T00:00:00")); |
222 assertEquals(0, Date.parse("1970-01T00:00Z")); | 222 assertEquals(0, Date.parse("1970-01T00:00")); |
223 assertEquals(0, Date.parse("1970-01Z")); | 223 assertEquals(0, Date.parse("1970-01")); |
224 | 224 |
225 assertEquals(0, Date.parse("1970T00:00:00.000+00:00")); | 225 assertEquals(0, Date.parse("1970T00:00:00.000+00:00")); |
226 assertEquals(0, Date.parse("1970T00:00:00.000-00:00")); | 226 assertEquals(0, Date.parse("1970T00:00:00.000-00:00")); |
227 assertEquals(0, Date.parse("1970T00:00:00.000Z")); | 227 assertEquals(0, Date.parse("1970T00:00:00.000Z")); |
228 assertEquals(0, Date.parse("1970T00:00:00.000Z")); | 228 assertEquals(0, Date.parse("1970T00:00:00.000")); |
229 assertEquals(0, Date.parse("1970T00:00:00Z")); | 229 assertEquals(0, Date.parse("1970T00:00:00")); |
230 assertEquals(0, Date.parse("1970T00:00Z")); | 230 assertEquals(0, Date.parse("1970T00:00")); |
231 assertEquals(0, Date.parse("1970Z")); | 231 assertEquals(0, Date.parse("1970")); |
232 | 232 |
233 assertEquals(0, Date.parse("+001970-01-01T00:00:00.000+00:00")); | 233 assertEquals(0, Date.parse("+001970-01-01T00:00:00.000+00:00")); |
234 assertEquals(0, Date.parse("+001970-01-01T00:00:00.000-00:00")); | 234 assertEquals(0, Date.parse("+001970-01-01T00:00:00.000-00:00")); |
235 assertEquals(0, Date.parse("+001970-01-01T00:00:00.000Z")); | 235 assertEquals(0, Date.parse("+001970-01-01T00:00:00.000Z")); |
236 assertEquals(0, Date.parse("+001970-01-01T00:00:00.000Z")); | 236 assertEquals(0, Date.parse("+001970-01-01T00:00:00.000")); |
237 assertEquals(0, Date.parse("+001970-01-01T00:00:00Z")); | 237 assertEquals(0, Date.parse("+001970-01-01T00:00:00")); |
238 assertEquals(0, Date.parse("+001970-01-01T00:00Z")); | 238 assertEquals(0, Date.parse("+001970-01-01T00:00")); |
239 assertEquals(0, Date.parse("+001970-01-01Z")); | 239 assertEquals(0, Date.parse("+001970-01-01")); |
240 | 240 |
241 assertEquals(0, Date.parse("+001970-01T00:00:00.000+00:00")); | 241 assertEquals(0, Date.parse("+001970-01T00:00:00.000+00:00")); |
242 assertEquals(0, Date.parse("+001970-01T00:00:00.000-00:00")); | 242 assertEquals(0, Date.parse("+001970-01T00:00:00.000-00:00")); |
243 assertEquals(0, Date.parse("+001970-01T00:00:00.000Z")); | 243 assertEquals(0, Date.parse("+001970-01T00:00:00.000Z")); |
244 assertEquals(0, Date.parse("+001970-01T00:00:00.000Z")); | 244 assertEquals(0, Date.parse("+001970-01T00:00:00.000")); |
245 assertEquals(0, Date.parse("+001970-01T00:00:00Z")); | 245 assertEquals(0, Date.parse("+001970-01T00:00:00")); |
246 assertEquals(0, Date.parse("+001970-01T00:00Z")); | 246 assertEquals(0, Date.parse("+001970-01T00:00")); |
247 assertEquals(0, Date.parse("+001970-01Z")); | 247 assertEquals(0, Date.parse("+001970-01")); |
248 | 248 |
249 assertEquals(0, Date.parse("+001970T00:00:00.000+00:00")); | 249 assertEquals(0, Date.parse("+001970T00:00:00.000+00:00")); |
250 assertEquals(0, Date.parse("+001970T00:00:00.000-00:00")); | 250 assertEquals(0, Date.parse("+001970T00:00:00.000-00:00")); |
251 assertEquals(0, Date.parse("+001970T00:00:00.000Z")); | 251 assertEquals(0, Date.parse("+001970T00:00:00.000Z")); |
252 assertEquals(0, Date.parse("+001970T00:00:00.000Z")); | 252 assertEquals(0, Date.parse("+001970T00:00:00.000")); |
253 assertEquals(0, Date.parse("+001970T00:00:00Z")); | 253 assertEquals(0, Date.parse("+001970T00:00:00")); |
254 assertEquals(0, Date.parse("+001970T00:00Z")); | 254 assertEquals(0, Date.parse("+001970T00:00")); |
255 assertEquals(0, Date.parse("+001970Z")); | 255 assertEquals(0, Date.parse("+001970")); |
256 | 256 |
257 // Check random date. | 257 // Check random date. |
258 assertEquals(70671003500, Date.parse("1972-03-28T23:50:03.500+01:00")); | 258 assertEquals(70671003500, Date.parse("1972-03-28T23:50:03.500+01:00")); |
259 assertEquals(70674603500, Date.parse("1972-03-28T23:50:03.500Z")); | 259 assertEquals(70674603500, Date.parse("1972-03-28T23:50:03.500Z")); |
260 assertEquals(70674603500, Date.parse("1972-03-28T23:50:03.500Z")); | 260 assertEquals(70674603500, Date.parse("1972-03-28T23:50:03.500")); |
261 assertEquals(70674603000, Date.parse("1972-03-28T23:50:03Z")); | 261 assertEquals(70674603000, Date.parse("1972-03-28T23:50:03")); |
262 assertEquals(70674600000, Date.parse("1972-03-28T23:50Z")); | 262 assertEquals(70674600000, Date.parse("1972-03-28T23:50")); |
263 assertEquals(70588800000, Date.parse("1972-03-28Z")); | 263 assertEquals(70588800000, Date.parse("1972-03-28")); |
264 | 264 |
265 assertEquals(68338203500, Date.parse("1972-03T23:50:03.500+01:00")); | 265 assertEquals(68338203500, Date.parse("1972-03T23:50:03.500+01:00")); |
266 assertEquals(68341803500, Date.parse("1972-03T23:50:03.500Z")); | 266 assertEquals(68341803500, Date.parse("1972-03T23:50:03.500Z")); |
267 assertEquals(68341803500, Date.parse("1972-03T23:50:03.500Z")); | 267 assertEquals(68341803500, Date.parse("1972-03T23:50:03.500")); |
268 assertEquals(68341803000, Date.parse("1972-03T23:50:03Z")); | 268 assertEquals(68341803000, Date.parse("1972-03T23:50:03")); |
269 assertEquals(68341800000, Date.parse("1972-03T23:50Z")); | 269 assertEquals(68341800000, Date.parse("1972-03T23:50")); |
270 assertEquals(68256000000, Date.parse("1972-03Z")); | 270 assertEquals(68256000000, Date.parse("1972-03")); |
271 | 271 |
272 assertEquals(63154203500, Date.parse("1972T23:50:03.500+01:00")); | 272 assertEquals(63154203500, Date.parse("1972T23:50:03.500+01:00")); |
273 assertEquals(63157803500, Date.parse("1972T23:50:03.500Z")); | 273 assertEquals(63157803500, Date.parse("1972T23:50:03.500Z")); |
274 assertEquals(63157803500, Date.parse("1972T23:50:03.500Z")); | 274 assertEquals(63157803500, Date.parse("1972T23:50:03.500")); |
275 assertEquals(63157803000, Date.parse("1972T23:50:03Z")); | 275 assertEquals(63157803000, Date.parse("1972T23:50:03")); |
276 assertEquals(63072000000, Date.parse("1972Z")); | 276 assertEquals(63072000000, Date.parse("1972")); |
277 | 277 |
278 assertEquals(70671003500, Date.parse("+001972-03-28T23:50:03.500+01:00")); | 278 assertEquals(70671003500, Date.parse("+001972-03-28T23:50:03.500+01:00")); |
279 assertEquals(70674603500, Date.parse("+001972-03-28T23:50:03.500Z")); | 279 assertEquals(70674603500, Date.parse("+001972-03-28T23:50:03.500Z")); |
280 assertEquals(70674603500, Date.parse("+001972-03-28T23:50:03.500Z")); | 280 assertEquals(70674603500, Date.parse("+001972-03-28T23:50:03.500")); |
281 assertEquals(70674603000, Date.parse("+001972-03-28T23:50:03Z")); | 281 assertEquals(70674603000, Date.parse("+001972-03-28T23:50:03")); |
282 assertEquals(70674600000, Date.parse("+001972-03-28T23:50Z")); | 282 assertEquals(70674600000, Date.parse("+001972-03-28T23:50")); |
283 assertEquals(70588800000, Date.parse("+001972-03-28Z")); | 283 assertEquals(70588800000, Date.parse("+001972-03-28")); |
284 | 284 |
285 assertEquals(68338203500, Date.parse("+001972-03T23:50:03.500+01:00")); | 285 assertEquals(68338203500, Date.parse("+001972-03T23:50:03.500+01:00")); |
286 assertEquals(68341803500, Date.parse("+001972-03T23:50:03.500Z")); | 286 assertEquals(68341803500, Date.parse("+001972-03T23:50:03.500Z")); |
287 assertEquals(68341803500, Date.parse("+001972-03T23:50:03.500Z")); | 287 assertEquals(68341803500, Date.parse("+001972-03T23:50:03.500")); |
288 assertEquals(68341803000, Date.parse("+001972-03T23:50:03Z")); | 288 assertEquals(68341803000, Date.parse("+001972-03T23:50:03")); |
289 assertEquals(68341800000, Date.parse("+001972-03T23:50Z")); | 289 assertEquals(68341800000, Date.parse("+001972-03T23:50")); |
290 assertEquals(68256000000, Date.parse("+001972-03Z")); | 290 assertEquals(68256000000, Date.parse("+001972-03")); |
291 | 291 |
292 assertEquals(63154203500, Date.parse("+001972T23:50:03.500+01:00")); | 292 assertEquals(63154203500, Date.parse("+001972T23:50:03.500+01:00")); |
293 assertEquals(63157803500, Date.parse("+001972T23:50:03.500Z")); | 293 assertEquals(63157803500, Date.parse("+001972T23:50:03.500Z")); |
294 assertEquals(63157803500, Date.parse("+001972T23:50:03.500Z")); | 294 assertEquals(63157803500, Date.parse("+001972T23:50:03.500")); |
295 assertEquals(63157803000, Date.parse("+001972T23:50:03Z")); | 295 assertEquals(63157803000, Date.parse("+001972T23:50:03")); |
296 assertEquals(63072000000, Date.parse("+001972Z")); | 296 assertEquals(63072000000, Date.parse("+001972")); |
297 | 297 |
298 | 298 |
299 // Ensure that ISO-years in the range 00-99 aren't translated to the range | 299 // Ensure that ISO-years in the range 00-99 aren't translated to the range |
300 // 1950..2049. | 300 // 1950..2049. |
301 assertEquals(-60904915200000, Date.parse("0040-01-01T00:00Z")); | 301 assertEquals(-60904915200000, Date.parse("0040-01-01")); |
302 assertEquals(-60273763200000, Date.parse("0060-01-01T00:00Z")); | 302 assertEquals(-60273763200000, Date.parse("0060-01-01")); |
303 assertEquals(-62167219200000, Date.parse("0000-01-01T00:00Z")); | 303 assertEquals(-62167219200000, Date.parse("0000-01-01")); |
304 assertEquals(-62167219200000, Date.parse("+000000-01-01T00:00Z")); | 304 assertEquals(-62167219200000, Date.parse("+000000-01-01")); |
305 | 305 |
306 // Test negative years. | 306 // Test negative years. |
307 assertEquals(-63429523200000, Date.parse("-000040-01-01Z")); | 307 assertEquals(-63429523200000, Date.parse("-000040-01-01")); |
308 assertEquals(-64060675200000, Date.parse("-000060-01-01Z")); | 308 assertEquals(-64060675200000, Date.parse("-000060-01-01")); |
309 assertEquals(-124397510400000, Date.parse("-001972-01-01Z")); | 309 assertEquals(-124397510400000, Date.parse("-001972-01-01")); |
310 | 310 |
311 // Check time-zones. | 311 // Check time-zones. |
312 assertEquals(70674603500, Date.parse("1972-03-28T23:50:03.500Z")); | 312 assertEquals(70674603500, Date.parse("1972-03-28T23:50:03.500Z")); |
313 for (var i = 0; i < 24; i++) { | 313 for (var i = 0; i < 24; i++) { |
314 var hh = (i < 10) ? "0" + i : "" + i; | 314 var hh = (i < 10) ? "0" + i : "" + i; |
315 for (var j = 0; j < 60; j += 15) { | 315 for (var j = 0; j < 60; j += 15) { |
316 var mm = (j < 10) ? "0" + j : "" + j; | 316 var mm = (j < 10) ? "0" + j : "" + j; |
317 var ms = (i * 60 + j) * 60000; | 317 var ms = (i * 60 + j) * 60000; |
318 var string = "1972-03-28T23:50:03.500-" + hh + ":" + mm; | 318 var string = "1972-03-28T23:50:03.500-" + hh + ":" + mm; |
319 assertEquals(70674603500 + ms, Date.parse(string), string); | 319 assertEquals(70674603500 + ms, Date.parse(string), string); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 delete Date.prototype.getUTCHours; | 352 delete Date.prototype.getUTCHours; |
353 delete Date.prototype.getUTCMinutes; | 353 delete Date.prototype.getUTCMinutes; |
354 delete Date.prototype.getUTCSeconds; | 354 delete Date.prototype.getUTCSeconds; |
355 delete Date.prototype.getUTCMilliseconds; | 355 delete Date.prototype.getUTCMilliseconds; |
356 date.toISOString(); | 356 date.toISOString(); |
357 | 357 |
358 (function TestDeleteToString() { | 358 (function TestDeleteToString() { |
359 assertTrue(delete Date.prototype.toString); | 359 assertTrue(delete Date.prototype.toString); |
360 assertTrue('[object Date]' !== Date()); | 360 assertTrue('[object Date]' !== Date()); |
361 })(); | 361 })(); |
OLD | NEW |