| 1 |
// Copyright 2009 the Sputnik authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-date-year-month-date-hours-minutes-seconds-ms |
| 6 |
info: | |
| 7 |
All of the arguments are optional, any arguments supplied are |
| 8 |
accepted but are completely ignored. A string is created and returned as |
| 9 |
if by the expression (new Date()).toString() |
| 10 |
es5id: 15.9.2.1_A2 |
| 11 |
description: Use various number arguments and various types of ones |
| 12 |
---*/ |
| 13 |
|
| 14 |
function isEqual(d1, d2) { |
| 15 |
if (d1 === d2) { |
| 16 |
return true; |
| 17 |
} else if (Math.abs(Date.parse(d1) - Date.parse(d2)) <= 1000) { |
| 18 |
return true; |
| 19 |
} else { |
| 20 |
return false; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
//CHECK#1 |
| 25 |
if (!isEqual(Date(), (new Date()).toString())) { |
| 26 |
$ERROR('#1: Date() is equal to (new Date()).toString()'); |
| 27 |
} |
| 28 |
|
| 29 |
//CHECK#2 |
| 30 |
if (!isEqual(Date(1), (new Date()).toString())) { |
| 31 |
$ERROR('#2: Date(1) is equal to (new Date()).toString()'); |
| 32 |
} |
| 33 |
|
| 34 |
//CHECK#3 |
| 35 |
if (!isEqual(Date(1970, 1), (new Date()).toString())) { |
| 36 |
$ERROR('#3: Date(1970, 1) is equal to (new Date()).toString()'); |
| 37 |
} |
| 38 |
|
| 39 |
//CHECK#4 |
| 40 |
if (!isEqual(Date(1970, 1, 1), (new Date()).toString())) { |
| 41 |
$ERROR('#4: Date(1970, 1, 1) is equal to (new Date()).toString()'); |
| 42 |
} |
| 43 |
|
| 44 |
//CHECK#5 |
| 45 |
if (!isEqual(Date(1970, 1, 1, 1), (new Date()).toString())) { |
| 46 |
$ERROR('#5: Date(1970, 1, 1, 1) is equal to (new Date()).toString()'); |
| 47 |
} |
| 48 |
|
| 49 |
//CHECK#6 |
| 50 |
if (!isEqual(Date(1970, 1, 1, 1), (new Date()).toString())) { |
| 51 |
$ERROR('#7: Date(1970, 1, 1, 1) is equal to (new Date()).toString()'); |
| 52 |
} |
| 53 |
|
| 54 |
//CHECK#8 |
| 55 |
if (!isEqual(Date(1970, 1, 1, 1, 0), (new Date()).toString())) { |
| 56 |
$ERROR('#8: Date(1970, 1, 1, 1, 0) is equal to (new Date()).toString()'); |
| 57 |
} |
| 58 |
|
| 59 |
//CHECK#9 |
| 60 |
if (!isEqual(Date(1970, 1, 1, 1, 0, 0), (new Date()).toString())) { |
| 61 |
$ERROR('#9: Date(1970, 1, 1, 1, 0, 0) is equal to (new Date()).toString()'); |
| 62 |
} |
| 63 |
|
| 64 |
//CHECK#10 |
| 65 |
if (!isEqual(Date(1970, 1, 1, 1, 0, 0, 0), (new Date()).toString())) { |
| 66 |
$ERROR('#10: Date(1970, 1, 1, 1, 0, 0, 0) is equal to (new Date()).toString()'); |
| 67 |
} |
| 68 |
|
| 69 |
//CHECK#11 |
| 70 |
if (!isEqual(Date(Number.NaN), (new Date()).toString())) { |
| 71 |
$ERROR('#11: Date(Number.NaN) is equal to (new Date()).toString()'); |
| 72 |
} |
| 73 |
|
| 74 |
//CHECK#12 |
| 75 |
if (!isEqual(Date(Number.POSITIVE_INFINITY), (new Date()).toString())) { |
| 76 |
$ERROR('#12: Date(Number.POSITIVE_INFINITY) is equal to (new Date()).toString()'); |
| 77 |
} |
| 78 |
|
| 79 |
//CHECK#13 |
| 80 |
if (!isEqual(Date(Number.NEGATIVE_INFINITY), (new Date()).toString())) { |
| 81 |
$ERROR('#13: Date(Number.NEGATIVE_INFINITY) is equal to (new Date()).toString()'); |
| 82 |
} |
| 83 |
|
| 84 |
//CHECK#14 |
| 85 |
if (!isEqual(Date(undefined), (new Date()).toString())) { |
| 86 |
$ERROR('#14: Date(undefined) is equal to (new Date()).toString()'); |
| 87 |
} |
| 88 |
|
| 89 |
//CHECK#15 |
| 90 |
if (!isEqual(Date(null), (new Date()).toString())) { |
| 91 |
$ERROR('#15: Date(null) is equal to (new Date()).toString()'); |
| 92 |
} |