• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/* 1. test case */
16var d = new Date(2015, 6, 9, 12, 13, 14, 121);
17
18assert (d.getFullYear() == 2015);
19assert (d.getUTCFullYear() == 2015);
20assert (d.getMonth() == 6);
21assert (d.getUTCMonth() == 6);
22assert (d.getDate() == 9);
23assert (d.getUTCDate() == 9);
24assert (d.getDay() == 4);
25assert (d.getUTCDay() == 4);
26assert (d.getHours() == 12);
27assert (d.getUTCHours() == (12 + d.getTimezoneOffset() / 60));
28assert (d.getMinutes() == 13);
29assert (d.getUTCMinutes() == 13);
30assert (d.getSeconds() == 14);
31assert (d.getUTCSeconds() == 14);
32assert (d.getMilliseconds() == 121);
33assert (d.getUTCMilliseconds() == 121);
34
35/* 2. test case */
36var d = new Date("2015-07-09T12:13:14.121+01:30");
37
38assert (d.getFullYear() == 2015);
39assert (d.getUTCFullYear() == 2015);
40assert (d.getMonth() == 6);
41assert (d.getUTCMonth() == 6);
42assert (d.getDate() == 9);
43assert (d.getUTCDate() == 9);
44assert (d.getDay() == 4);
45assert (d.getUTCDay() == 4);
46assert (d.getHours() == Math.floor(12 - 1.5 + d.getTimezoneOffset() / 60));
47assert (d.getUTCHours() == Math.floor(12 - 1.5));
48assert (d.getMinutes() == 43);
49assert (d.getUTCMinutes() == 43);
50assert (d.getSeconds() == 14);
51assert (d.getUTCSeconds() == 14);
52assert (d.getMilliseconds() == 121);
53assert (d.getUTCMilliseconds() == 121);
54
55/* 3. test case */
56var d = new Date(0);
57
58assert (d.getFullYear() == 1970);
59assert (d.getUTCFullYear() == 1970);
60assert (d.getMonth() == 0);
61assert (d.getUTCMonth() == 0);
62assert (d.getDate() == 1);
63assert (d.getUTCDate() == 1);
64assert (d.getDay() == 4);
65assert (d.getUTCDay() == 4);
66assert (d.getHours() == 0 - (d.getTimezoneOffset() / 60));
67assert (d.getUTCHours() == 0);
68assert (d.getMinutes() == 0);
69assert (d.getUTCMinutes() == 0);
70assert (d.getSeconds() == 0);
71assert (d.getUTCSeconds() == 0);
72assert (d.getMilliseconds() == 0);
73assert (d.getUTCMilliseconds() == 0);
74
75/* 4. test case */
76var d = new Date("abcd");
77assert (isNaN (d));
78
79assert (isNaN (d.getFullYear()));
80assert (isNaN (d.getUTCFullYear()));
81assert (isNaN (d.getMonth()));
82assert (isNaN (d.getUTCMonth()));
83assert (isNaN (d.getDate()));
84assert (isNaN (d.getUTCDate()));
85assert (isNaN (d.getDay()));
86assert (isNaN (d.getUTCDay()));
87assert (isNaN (d.getHours()));
88assert (isNaN (d.getUTCHours()));
89assert (isNaN (d.getMinutes()));
90assert (isNaN (d.getUTCMinutes()));
91assert (isNaN (d.getSeconds()));
92assert (isNaN (d.getUTCSeconds()));
93assert (isNaN (d.getMilliseconds()));
94assert (isNaN (d.getUTCMilliseconds()));
95assert (isNaN (d.getTimezoneOffset()));
96
97/* 5. test case */
98assert (new Date(2013, -1).getMonth() === 11);
99assert (new Date(-2, -2).getFullYear() === -3);
100assert (new Date(-1, -1).getFullYear() === -2);
101assert (new Date(-1, -1, -1).getMonth() === 10);
102assert (new Date(-1, -1, -1, -1).getDate() === 28);
103assert (new Date(-1, -1, -1, -1, -1).getHours() === 22);
104assert (new Date(-1, -1, -1, -1, -1, -1).getMinutes() === 58);
105assert (new Date(-1, -1, -1, -1, -1, -1, -1).getSeconds() === 58);
106assert (new Date(-1, -1, -1, -1, -1, -1, -1, -1).getMilliseconds() === 999);
107