Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / script-tests / date-big-setdate.js
blobb0f6cb2294676a8b8f40577c71177478730981d2
1 description(
2 'This test checks for regression against: <a href="http://bugs.webkit.org/show_bug.cgi?id=3381"> 3381 Date.prototype.setDate() incorrect for values >=128.</a> <br /> <a href="http://bugs.webkit.org/show_bug.cgi?id=12975">12975: DST changes in US affect JavaScript date calculations</a>'
3 );
6 var validVars = false;
7 var curValue;
8 var success = true;
9 var millisecondsPerDay = 1000 * 60 * 60 * 24;
10 var millisecondsPerHour = 1000 * 60 * 60;
12 for (var i = 116; i < 126; i++) {
13 var d = new Date(0);
14 d.setDate(i);
15 if (validVars)
16 shouldBe("d.valueOf() - curValue", "millisecondsPerDay");
18 curValue = d.valueOf();
19 validVars = true;
22 var testCases = [];
23 if ((new Date(2009, 9, 1)).toString().match("PDT")) {
24 // Added a special case that should represent a change in DST. DST did not actually
25 // change on this date but because of the wierdness of how JavaScriptDates are
26 // expected to interpolate DST as opposed to reflect acurate history, this day
27 // (April 5th 1970) should show a DST change.
28 testCases.push([new Date(0), 97, 98]);
30 // Added more special cases. These dates match the recent DST changes in the US.
31 // These tests check that the new changes are correctly propogated to the past and
32 // all of the tests should show DST occurring on the same date.
33 testCases.push([new Date(1970, 0,0,0,0,0,0), 98, 99]);
34 testCases.push([new Date(1998, 0,0,0,0,0,0), 98, 99]);
35 testCases.push([new Date(2026, 0,0,0,0,0,0), 98, 99]);
36 testCases.push([new Date(2054, 0,0,0,0,0,0), 98, 99]);
39 var errors = [];
40 for (var i = 0; i < testCases.length; i++) {
41 var c = testCases[i][0];
42 var d = new Date(c);
43 c.setDate(testCases[i][1]);
44 d.setDate(testCases[i][2]);
46 var actual = d.valueOf() - c.valueOf();
47 var expected = millisecondsPerDay - millisecondsPerHour;
48 if (actual != expected) {
49 errors.push("Unexpected difference between two days (expected: " + expected + ", actual: " + actual + ") for " + testCases[i][0]);
53 if (errors.length) {
54 testFailed(errors.length + "/" + testCases.length + " tests were failed: " + errors.join(", "));
55 } else {
56 testPassed("Passed all tests for DST (or skipped the tests if your timezone isn't PST/PDT)");