test/script/basic/date.js

changeset 3
da1e581c933b
child 7
5a1b0714df0e
equal deleted inserted replaced
2:6031a0bc0ae2 3:da1e581c933b
1 /*
2 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 * Basic checks for Date constructor.
26 * FIXME: add more checks
27 *
28 * @test
29 * @option -timezone=Asia/Calcutta
30 * @run
31 */
32
33 // check arity of tricky functions
34 print("Date.length = " + Date.length);
35 print("Date.UTC.length = " + Date.UTC.length);
36 print("Date.prototype.setSeconds.length = " + Date.prototype.setSeconds.length);
37 print("Date.prototype.setUTCSeconds.length = " + Date.prototype.setUTCSeconds.length);
38 print("Date.prototype.setMinutes.length = " + Date.prototype.setMinutes.length);
39 print("Date.prototype.setUTCMinutes.length = " + Date.prototype.setUTCMinutes.length);
40 print("Date.prototype.setHours.length = " + Date.prototype.setHours.length);
41 print("Date.prototype.setUTCHours.length = " + Date.prototype.setUTCHours.length);
42 print("Date.prototype.setMonth.length = " + Date.prototype.setMonth.length);
43 print("Date.prototype.setUTCMonth.length = " + Date.prototype.setUTCMonth.length);
44 print("Date.prototype.setFullYear.length = " + Date.prototype.setFullYear.length);
45 print("Date.prototype.setUTCFullYear.length = " + Date.prototype.setUTCFullYear.length);
46
47 function printDate(d) {
48 print(d.getMinutes());
49 print(d.getSeconds());
50 print(d.getMilliseconds());
51 print(d.getUTCDate());
52 print(d.getUTCDay());
53 print(d.getUTCMonth());
54 print(d.getUTCFullYear());
55 print(d.getUTCHours());
56 print(d.getUTCMinutes());
57 print(d.getUTCSeconds());
58 print(d.getUTCMilliseconds());
59 print(d.toISOString());
60 print(d.toUTCString());
61 print(d.toString());
62 print(d.toLocaleString());
63 print(d.toLocaleDateString());
64 print(d.toLocaleTimeString());
65 print(d.toDateString());
66 print(d.toTimeString());
67 print(d.toJSON());
68 }
69
70 var d = new Date(2011, 4, 3, 17, 1, 1, 0);
71 printDate(d);
72
73 d.setUTCMinutes(40, 34);
74 printDate(d);
75
76 d = new Date(Date.UTC(2000, 10, 1, 1, 1, 1, 1));
77 printDate(d);
78
79 d = new Date(0);
80 d.setFullYear(2012);
81 d.setMonth(1);
82 d.setDate(2);
83 d.setHours(3);
84 d.setMinutes(3);
85 d.setSeconds(4);
86 d.setMilliseconds(5);
87 printDate(d);
88
89 d = new Date(0);
90 d.setUTCFullYear(2012);
91 d.setUTCMonth(1);
92 d.setUTCDate(2);
93 d.setUTCHours(3);
94 d.setUTCMinutes(4);
95 d.setUTCSeconds(5);
96 d.setUTCMilliseconds(6);
97 printDate(d);
98
99 d = new Date(0);
100 d.setTime(1000);
101 printDate(d);

mercurial