date.js revision 877:cf4d2252d444
1/*
2 * Copyright (c) 2010, 2013, 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
34print("Date.length = " + Date.length);
35print("Date.UTC.length = " + Date.UTC.length);
36print("Date.prototype.setSeconds.length = " + Date.prototype.setSeconds.length);
37print("Date.prototype.setUTCSeconds.length = " + Date.prototype.setUTCSeconds.length);
38print("Date.prototype.setMinutes.length = " + Date.prototype.setMinutes.length);
39print("Date.prototype.setUTCMinutes.length = " + Date.prototype.setUTCMinutes.length);
40print("Date.prototype.setHours.length = " + Date.prototype.setHours.length);
41print("Date.prototype.setUTCHours.length = " + Date.prototype.setUTCHours.length);
42print("Date.prototype.setMonth.length = " + Date.prototype.setMonth.length);
43print("Date.prototype.setUTCMonth.length = " + Date.prototype.setUTCMonth.length);
44print("Date.prototype.setFullYear.length = " + Date.prototype.setFullYear.length);
45print("Date.prototype.setUTCFullYear.length = " + Date.prototype.setUTCFullYear.length);
46
47function 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
70var d = new Date(2011, 4, 3, 17, 1, 1, 0);
71printDate(d);
72
73d.setUTCMinutes(40, 34);
74printDate(d);
75
76d = new Date(Date.UTC(2000, 10, 1, 1, 1, 1, 1));
77printDate(d);
78
79d = new Date(0);
80d.setFullYear(2012);
81d.setMonth(1);
82d.setDate(2);
83d.setHours(3);
84d.setMinutes(3);
85d.setSeconds(4);
86d.setMilliseconds(5);
87printDate(d);
88
89d = new Date(0);
90d.setUTCFullYear(2012);
91d.setUTCMonth(1);
92d.setUTCDate(2);
93d.setUTCHours(3);
94d.setUTCMinutes(4);
95d.setUTCSeconds(5);
96d.setUTCMilliseconds(6);
97printDate(d);
98
99d = new Date(0);
100d.setTime(1000);
101printDate(d);
102