Debian Codegraph @

rhino/testsrc/tests/ecma/Date/15.9.4.2.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = '15.9.4.2.js';
7
8 /**
9 File Name: 15.9.4.2.js
10 ECMA Section: 15.9.4.2 Date.parse()
11 Description: The parse() function applies the to ToString() operator
12 to its argument and interprets the resulting string as
13 a date. It returns a number, the UTC time value
14 corresponding to the date.
15
16 The string may be interpreted as a local time, a UTC
17 time, or a time in some other time zone, depending on
18 the contents of the string.
19
20 (need to test strings containing stuff with the time
21 zone specified, and verify that parse() returns the
22 correct GMT time)
23
24 so for any Date object x, all of these things should
25 be equal:
26
27 value tested in function:
28 x.valueOf() test_value()
29 Date.parse(x.toString()) test_tostring()
30 Date.parse(x.toGMTString()) test_togmt()
31
32 Date.parse(x.toLocaleString()) is not required to
33 produce the same number value as the preceeding three
34 expressions. in general the value produced by
35 Date.parse is implementation dependent when given any
36 string value that could not be produced in that
37 implementation by the toString or toGMTString method.
38
39 value tested in function:
40 Date.parse( x.toLocaleString()) test_tolocale()
41
42 Author: [email protected]
43 Date: 10 july 1997
44
45 */
46
47 var VERSION = "ECMA_1";
48 startTest();
49 var SECTION = "15.9.4.2";
50 var TITLE = "Date.parse()";
51
52 var TIME = 0;
53 var UTC_YEAR = 1;
54 var UTC_MONTH = 2;
55 var UTC_DATE = 3;
56 var UTC_DAY = 4;
57 var UTC_HOURS = 5;
58 var UTC_MINUTES = 6;
59 var UTC_SECONDS = 7;
60 var UTC_MS = 8;
61
62 var YEAR = 9;
63 var MONTH = 10;
64 var DATE = 11;
65 var DAY = 12;
66 var HOURS = 13;
67 var MINUTES = 14;
68 var SECONDS = 15;
69 var MS = 16;
70 var TYPEOF = "object";
71
72 // for TCMS, the gTestcases array must be global.
73 writeHeaderToLog("15.9.4.2 Date.parse()" );
74
75 // Dates around 1970
76
77 addNewTestCase( new Date(0),
78 "new Date(0)",
79 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
80
81 addNewTestCase( new Date(-1),
82 "new Date(-1)",
83 [-1,1969,11,31,3,23,59,59,999,1969,11,31,3,15,59,59,999] );
84 addNewTestCase( new Date(28799999),
85 "new Date(28799999)",
86 [28799999,1970,0,1,4,7,59,59,999,1969,11,31,3,23,59,59,999] );
87 addNewTestCase( new Date(28800000),
88 "new Date(28800000)",
89 [28800000,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
90
91 // Dates around 2000
92
93 addNewTestCase( new Date(946684799999),
94 "new Date(946684799999)",
95 [946684799999,1999,11,31,5,23,59,59,999,1999,11,31,5,15,59,59,999] );
96 addNewTestCase( new Date(946713599999),
97 "new Date(946713599999)",
98 [946713599999,2000,0,1,6,7,59,59,999,1999,11,31,5,23,59,59,999] );
99 addNewTestCase( new Date(946684800000),
100 "new Date(946684800000)",
101 [946684800000,2000,0,1,6,0,0,0,0,1999,11,31,5, 16,0,0,0] );
102 addNewTestCase( new Date(946713600000),
103 "new Date(946713600000)",
104 [946713600000,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
105
106 // Dates around 1900
107
108 addNewTestCase( new Date(-2208988800000),
109 "new Date(-2208988800000)",
110 [-2208988800000,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
111
112 addNewTestCase( new Date(-2208988800001),
113 "new Date(-2208988800001)",
114 [-2208988800001,1899,11,31,0,23,59,59,999,1899,11,31,0,15,59,59,999] );
115
116 addNewTestCase( new Date(-2208960000001),
117 "new Date(-2208960000001)",
118 [-2208960000001,1900,0,1,1,7,59,59,0,1899,11,31,0,23,59,59,999] );
119 addNewTestCase( new Date(-2208960000000),
120 "new Date(-2208960000000)",
121 [-2208960000000,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
122 addNewTestCase( new Date(-2208959999999),
123 "new Date(-2208959999999)",
124 [-2208959999999,1900,0,1,1,8,0,0,1,1900,0,1,1,0,0,0,1] );
125
126 // Dates around Feb 29, 2000
127
128 var PST_FEB_29_2000 = UTC_FEB_29_2000 + 8*msPerHour;
129
130 addNewTestCase( new Date(UTC_FEB_29_2000),
131 "new Date(" + UTC_FEB_29_2000 +")",
132 [UTC_FEB_29_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] );
133 addNewTestCase( new Date(PST_FEB_29_2000),
134 "new Date(" + PST_FEB_29_2000 +")",
135 [PST_FEB_29_2000,2000,0,1,6,8.0,0,0,2000,0,1,6,0,0,0,0]);
136
137 // Dates around Jan 1 2005
138
139 var PST_JAN_1_2005 = UTC_JAN_1_2005 + 8*msPerHour;
140
141 addNewTestCase( new Date(UTC_JAN_1_2005),
142 "new Date("+ UTC_JAN_1_2005 +")",
143 [UTC_JAN_1_2005,2005,0,1,6,0,0,0,0,2004,11,31,5,16,0,0,0] );
144 addNewTestCase( new Date(PST_JAN_1_2005),
145 "new Date("+ PST_JAN_1_2005 +")",
146 [PST_JAN_1_2005,2005,0,1,6,8,0,0,0,2005,0,1,6,0,0,0,0] );
147
148
149 test();
150
151 function addNewTestCase( DateCase, DateString, ResultArray ) {
152 DateCase = DateCase;
153
154 new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME], DateCase.getTime() );
155 new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME], DateCase.valueOf() );
156 new TestCase( SECTION, "Date.parse(" + DateCase.toString() +")", Math.floor(ResultArray[TIME]/1000)*1000, Date.parse(DateCase.toString()) );
157 new TestCase( SECTION, "Date.parse(" + DateCase.toGMTString() +")", Math.floor(ResultArray[TIME]/1000)*1000, Date.parse(DateCase.toGMTString()) );
158 }