Wed, 15 May 2013 20:21:59 +0200
8014647: Allow class-based overrides to be initialized with a ScriptFunction
Reviewed-by: hannesw, jlaskey, sundar
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 */
24 /**
25 * NASHORN-627 : Make NativeDate fully ECMA compliant
26 *
27 * @test
28 * @option -timezone=Europe/Vienna
29 * @run
30 */
32 // constructor, toString, getTime, toISOString. EXPECTED is from spidermonkey
33 function printDate(d) {
34 print(d, d.getTime(), d.toISOString());
35 }
36 for (var i = -10; i < 380; i++) {
37 printDate(new Date(70, 0, i));
38 }
39 for (var i = -10; i < 380; i++) {
40 printDate(new Date(2011, 0, i, 17, 0, 59));
41 }
42 for (var i = -10; i < 380; i++) {
43 printDate(new Date(2012, 0, i, 12, 30, 10, 500));
44 }
46 [
47 '2012-03-01 09:00',
48 '2012-03-01 08:00 +0000',
49 '2012/03/01 08:00 GMT+0000',
50 '03/01/2012, 08:00 AM UT',
51 '01 March 12 08:00 +0000',
52 'Mar 01 08:00:00 UT 2012',
53 'Sat, 01-Mar-2012 08:00:00 UT',
54 'Sat, 01 Mar 2012 08:00:00 UT',
55 'Mar 01 2012 08:00:00 UT',
56 'Saturday, 01-Mar-2012 08:00:00 UT',
57 '01 Mar 2012 08:00 +0000',
59 'Sat, 01-Mar-2012 03:00:00 EST',
60 'Sat, 01 Mar 2012 03:00:00 EST',
61 'Mar 01 2012 03:00:00 EST',
62 'Saturday, 01-Mar-2012 03:00:00 EST',
63 '01 Mar 2012 03:00 -0500',
65 'Sat, 01-Mar-2012 04:00:00 EDT',
66 'Sat, 01 Mar 2012 04:00:00 EDT',
67 'Mar 01 2012 04:00:00 EDT',
68 'Saturday, 01-Mar-2012 04:00:00 EDT',
69 '01 Mar 2012 04:00 -0400',
71 'Sat, 01-Mar-2012 02:00:00 CST',
72 'Sat, 01 Mar 2012 02:00:00 CST',
73 'Mar 01 2012 02:00:00 CST',
74 'Saturday, 01-Mar-2012 02:00:00 CST',
75 '01 Mar 2012 02:00 -0600',
77 'Sat, 01-Mar-2012 03:00:00 CDT',
78 'Sat, 01 Mar 2012 03:00:00 CDT',
79 'Mar 01 2012 03:00:00 CDT',
80 'Saturday, 01-Mar-2012 03:00:00 CDT',
81 '01 Mar 2012 03:00 -0500',
83 'Sat, 01-Mar-2012 01:00:00 MST',
84 'Sat, 01 Mar 2012 01:00:00 MST',
85 'Mar 01 2012 01:00:00 MST',
86 'Saturday, 01-Mar-2012 01:00:00 MST',
87 '01 Mar 2012 01:00 -0700',
89 'Sat, 01-Mar-2012 02:00:00 MDT',
90 'Sat, 01 Mar 2012 02:00:00 MDT',
91 'Mar 01 2012 02:00:00 MDT',
92 'Saturday, 01-Mar-2012 02:00:00 MDT',
93 '01 Mar 2012 02:00 -0600',
95 'Sat, 01-Mar-2012 00:00:00 PST',
96 'Sat, 01 Mar 2012 00:00:00 PST',
97 'Mar 01 2012 00:00:00 PST',
98 'Saturday, 01-Mar-2012 00:00:00 PST',
99 '01 Mar 2012 00:00 -0800',
101 'Sat, 01-Mar-2012 01:00:00 PDT',
102 'Sat, 01 Mar 2012 01:00:00 PDT',
103 'Mar 01 2012 01:00:00 PDT',
104 'Saturday, 01-Mar-2012 01:00:00 PDT',
105 '01 Mar 2012 01:00 -0700'
106 ].forEach(function(s) {
107 parseDate(s, 1330588800000);
108 });
110 [
111 '2012-01-01T08:00:00.000Z',
112 '2012-01-01T08:00:00Z',
113 '2012-01-01T08:00Z',
114 '2012-01T08:00:00.000Z',
115 '2012T08:00:00.000Z',
116 '2012T08:00Z',
117 '2012-01T00:00:00.000-08:00',
118 '2012-01T00:00:00.000-08:00'
119 ].forEach(function(s) {
120 parseDate(s, 1325404800000);
121 });
123 [
124 'Mon, 25 Dec 1995 13:30:00 GMT+0430',
125 '1995/12/25 13:30 GMT+0430',
126 '12/25/1995, 01:30 PM +04:30',
127 'Dec 25 1995 13:30:00 +0430'
128 ].forEach(function(s) {
129 parseDate(s, 819882000000);
130 });
132 // invalid iso dates
133 [
134 '2000-01-01TZ',
135 '2000-01-01T60Z',
136 '2000-01-01T60:60Z',
137 '2000-01-0108:00Z',
138 '2000-01-01T08Z'
139 ].forEach(function(s) {
140 parseDate(s, NaN);
141 });
143 // milliseconds
144 parseDate('2012-01T08:00:00.001Z', 1325404800001);
145 parseDate('2012-01T08:00:00.099Z', 1325404800099);
146 parseDate('2012-01T08:00:00.999Z', 1325404800999);
148 function parseDate(s, t) {
149 var d = new Date(s.toString());
150 if (d.getTime() == t || (isNaN(d.getTime() && isNaN(t)))) {
151 print('ok', d);
152 } else {
153 print('expected', t, 'got', d.getTime());
154 }
155 }