1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is JavaScript Engine testing utilities.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2008
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s): Bruce Hoult
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 //-----------------------------------------------------------------------------
39 var BUGNUMBER = 430930;
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
47 return new Date(d).toISOString();
50 function check(s, millis){
51 description = "Date.parse('"+s+"') == '"+iso(millis)+"'";
53 actual = Date.parse(s);
54 reportCompare(expected, actual, description);
57 function dd(year, month, day, hour, minute, second, millis){
58 return Date.UTC(year, month-1, day, hour, minute, second, millis);
62 return d.getTimezoneOffset() * 60000;
65 function TZInMonth(month){
66 return TZAtDate(new Date(dd(2009,month,1,0,0,0,0)));
72 printBugNumber(BUGNUMBER);
76 CurrTZ = TZAtDate(new Date());
78 // formats with explicit timezone
79 check("2009-07-23T19:53:21.001+12:00", dd(2009,7,23,7,53,21,1));
80 check("2009-07-23T19:53:21+12:00", dd(2009,7,23,7,53,21,0));
81 check("2009-07-23T19:53+12:00", dd(2009,7,23,7,53,0,0));
83 check("2009-07T19:53:21.001+12:00", dd(2009,7,1,7,53,21,1));
84 check("2009-07T19:53:21+12:00", dd(2009,7,1,7,53,21,0));
85 check("2009-07T19:53+12:00", dd(2009,7,1,7,53,0,0));
87 check("2009T19:53:21.001+12:00", dd(2009,1,1,7,53,21,1));
88 check("2009T19:53:21+12:00", dd(2009,1,1,7,53,21,0));
89 check("2009T19:53+12:00", dd(2009,1,1,7,53,0,0));
91 check("T19:53:21.001+12:00", dd(1970,1,1,7,53,21,1));
92 check("T19:53:21+12:00", dd(1970,1,1,7,53,21,0));
93 check("T19:53+12:00", dd(1970,1,1,7,53,0,0));
95 // formats without timezone uses the timezone as at that date
96 check("2009-07-23T19:53:21.001", dd(2009,7,23,19,53,21,1)+JulTZ);
97 check("2009-07-23T19:53:21", dd(2009,7,23,19,53,21,0)+JulTZ);
98 check("2009-07-23T19:53", dd(2009,7,23,19,53,0,0)+JulTZ);
100 check("2009-07T19:53:21.001", dd(2009,7,1,19,53,21,1)+JulTZ);
101 check("2009-07T19:53:21", dd(2009,7,1,19,53,21,0)+JulTZ);
102 check("2009-07T19:53", dd(2009,7,1,19,53,0,0)+JulTZ);
104 check("2009T19:53:21.001", dd(2009,1,1,19,53,21,1)+JanTZ);
105 check("2009T19:53:21", dd(2009,1,1,19,53,21,0)+JanTZ);
106 check("2009T19:53", dd(2009,1,1,19,53,0,0)+JanTZ);
108 check("T19:53:21.001", dd(1970,1,1,19,53,21,1)+JanTZ);
109 check("T19:53:21", dd(1970,1,1,19,53,21,0)+JanTZ);
110 check("T19:53", dd(1970,1,1,19,53,0,0)+JanTZ);
112 // with no time at all assume UTC
113 check("2009-07-23", dd(2009,7,23,0,0,0,0));
114 check("2009-07", dd(2009,7,1,0,0,0,0));
115 check("2009", dd(2009,1,1,0,0,0,0));
119 check("2009-13-23T19:53:21.001+12:00", NaN);
120 check("2009-07-32T19:53:21.001+12:00", NaN);
121 check("2009-07-23T25:53:21.001+12:00", NaN);
122 check("2009-07-23T19:60:21.001+12:00", NaN);
123 check("2009-07-23T19:53:60.001+12:00", NaN);
124 check("2009-07-23T19:53:21.001+24:00", NaN);
125 check("2009-07-23T19:53:21.001+12:60", NaN);
128 check("2009-06-30T19:53:21.001+12:00", dd(2009,6,30,7,53,21,1));
129 check("2009-06-31T19:53:21.001+12:00", NaN);
130 check("2009-02-28T19:53:21.001+12:00", dd(2009,2,28,7,53,21,1));
131 check("2009-02-29T19:53:21.001+12:00", NaN);
132 check("2008-02-29T19:53:21.001+12:00", dd(2008,2,29,7,53,21,1));
133 check("2008-02-30T19:53:21.001+12:00", NaN);
135 // limits of representation
136 check("-271821-04-19T23:59:59.999Z", NaN);
137 check("-271821-04-20", -8.64e15);
138 check("+275760-09-13", 8.64e15);
139 check("+275760-09-13T00:00:00.001Z", NaN);
141 check("-269845-07-23T19:53:21.001+12:00", dd(-269845,7,23,7,53,21,1));
142 check("+273785-07-23T19:53:21.001+12:00", dd(273785,7,23,7,53,21,1));
145 check("2009-07-23T19:53:21.001Z", dd(2009,7,23,19,53,21,1));
146 check("+002009-07-23T19:53:21.001Z", dd(2009,7,23,19,53,21,1));
148 // different timezones
149 check("2009-07-23T19:53:21.001+12:00", dd(2009,7,23,7,53,21,1));
150 check("2009-07-23T00:53:21.001-07:00", dd(2009,7,23,7,53,21,1));
153 check("2009-07-23T00:00:00.000-07:00", dd(2009,7,23,7,0,0,0));
154 check("2009-07-23T24:00:00.000-07:00", dd(2009,7,24,7,0,0,0));