Browse Source

some basic Date built-in tests

pull/1/head
Sami Vaarala 12 years ago
parent
commit
7597aa576d
  1. 28
      testcases/test-builtin-date-canceling.js
  2. 12
      testcases/test-builtin-date-invalid-date.js
  3. 22
      testcases/test-builtin-date-midnight-1970.js
  4. 58
      testcases/test-builtin-date-tzoffset.js

28
testcases/test-builtin-date-canceling.js

@ -0,0 +1,28 @@
/*===
1970-01-01T00:00:00.000Z
1970-01-01T00:00:00.000Z
===*/
function hugeCancelingComponents() {
var d = new Date(0);
print(d.toISOString());
// This call does not change the internal time value of the Date:
// the second and millisecond counts will be converted with
// ToInteger() and will cancel out before TimeClip() is applied.
//
// Note, in particular, that huge components (which are outside
// even 64-bit range) must not lead to an invalid time value if
// they "cancel out". For the implementation, this means that
// Date setters must operate with doubles.
d.setUTCSeconds(1e120,-1e123)
print(d.toISOString());
}
try {
hugeCancelingComponents();
} catch (e) {
print(e.name);
}

12
testcases/test-builtin-date-invalid-date.js

@ -0,0 +1,12 @@
/*===
Invalid Date
===*/
/* The required value was not specified in E5 or E5.1; E6 draft
* indicates "Invalid Date" is what is required, and V8 agrees:
*
* http://people.mozilla.org/~jorendorff/es6-draft.html#sec-D
*/
print(new Date(Number.POSITIVE_INFINITY).toString());

22
testcases/test-builtin-date-midnight-1970.js

@ -0,0 +1,22 @@
/*===
1970-01-01T00:00:00.000Z
0 Infinity
===*/
/* Midnight Jan 1, 1970 time value is +0 (check sign). E5.1 Section 15.9.1.1. */
function midnight1970Test() {
var d;
d = new Date(Date.UTC(1970, 0, 1, 0, 0, 0, 0));
print(d.toISOString());
print(d.getTime(), 1 / d.getTime()); // 1/x to test sign
}
try {
midnight1970Test();
} catch (e) {
print(e.name);
}

58
testcases/test-builtin-date-tzoffset.js

@ -0,0 +1,58 @@
/*===
no output expected
===*/
/* The underlying implementation of Date.prototype.getTimezoneOffset()
* currently uses locale-specific datetime handling functions on UNIX.
* Although we can't check that the implementation works correctly, we
* can check that it doesn't fail with year values outside 32-bit UNIX
* timestamp range (1970-2038).
*
* (Of course, some UNIX systems provide a 64-bit timestamp and have no
* issues covering the Ecmascript date range.)
*/
function test(tv) {
var d = new Date(tv);
var t;
t = d.getTimezoneOffset();
function err(msg) {
print('timevalue ' + tv + ': ' + msg +
' (typeof t=' + typeof t + ', t=' + t + ')');
}
if (typeof t !== 'number') {
return err('invalid return type');
}
if (t !== Math.floor(t)) {
return err('offset not a whole number');
}
if (!(t >= -12 * 60 && t <= 12 * 60)) {
return err('offset not within expected +/- 12h range');
}
}
var years = [
1969, 1970, 1980, 1990, 2000, 2010, 2020, 2030, 2037, 2038, 2039,
-250000, -100000, 100000, 250000
];
var i;
print('no output expected');
try {
test(Date.now());
for (i = 0; i < years.length; i++) {
// Test January and July to get any DST effects
test(Date.UTC(years[i], 0, 1, 0, 0, 0, 0));
test(Date.UTC(years[i], 6, 1, 0, 0, 0, 0));
}
} catch (e) {
print(e.name);
}
Loading…
Cancel
Save