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 Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 var SECTION = "15.9.4.3";
41 var TITLE = "Date.UTC( year, month, date, hours, minutes, seconds, ms )";
45 addNewTestCase( Date.UTC( 1970,0,1,0,0,0,0),
46 "Date.UTC( 1970,0,1,0,0,0,0)",
47 utc(1970,0,1,0,0,0,0) );
49 addNewTestCase( Date.UTC( 1969,11,31,23,59,59,999),
50 "Date.UTC( 1969,11,31,23,59,59,999)",
51 utc(1969,11,31,23,59,59,999) );
52 addNewTestCase( Date.UTC( 1972,1,29,23,59,59,999),
53 "Date.UTC( 1972,1,29,23,59,59,999)",
54 utc(1972,1,29,23,59,59,999) );
55 addNewTestCase( Date.UTC( 1972,2,1,23,59,59,999),
56 "Date.UTC( 1972,2,1,23,59,59,999)",
57 utc(1972,2,1,23,59,59,999) );
58 addNewTestCase( Date.UTC( 1968,1,29,23,59,59,999),
59 "Date.UTC( 1968,1,29,23,59,59,999)",
60 utc(1968,1,29,23,59,59,999) );
61 addNewTestCase( Date.UTC( 1968,2,1,23,59,59,999),
62 "Date.UTC( 1968,2,1,23,59,59,999)",
63 utc(1968,2,1,23,59,59,999) );
64 addNewTestCase( Date.UTC( 1969,0,1,0,0,0,0),
65 "Date.UTC( 1969,0,1,0,0,0,0)",
66 utc(1969,0,1,0,0,0,0) );
67 addNewTestCase( Date.UTC( 1969,11,31,23,59,59,1000),
68 "Date.UTC( 1969,11,31,23,59,59,1000)",
69 utc(1970,0,1,0,0,0,0) );
70 addNewTestCase( Date.UTC( 1969,Number.NaN,31,23,59,59,999),
71 "Date.UTC( 1969,Number.NaN,31,23,59,59,999)",
72 utc(1969,Number.NaN,31,23,59,59,999) );
76 addNewTestCase( Date.UTC( 1999,11,31,23,59,59,999),
77 "Date.UTC( 1999,11,31,23,59,59,999)",
78 utc(1999,11,31,23,59,59,999) );
79 addNewTestCase( Date.UTC( 2000,0,1,0,0,0,0),
80 "Date.UTC( 2000,0,1,0,0,0,0)",
81 utc(2000,0,1,0,0,0,0) );
84 addNewTestCase( Date.UTC( 1899,11,31,23,59,59,999),
85 "Date.UTC( 1899,11,31,23,59,59,999)",
86 utc(1899,11,31,23,59,59,999) );
87 addNewTestCase( Date.UTC( 1900,0,1,0,0,0,0),
88 "Date.UTC( 1900,0,1,0,0,0,0)",
89 utc(1900,0,1,0,0,0,0) );
90 addNewTestCase( Date.UTC( 1973,0,1,0,0,0,0),
91 "Date.UTC( 1973,0,1,0,0,0,0)",
92 utc(1973,0,1,0,0,0,0) );
93 addNewTestCase( Date.UTC( 1776,6,4,12,36,13,111),
94 "Date.UTC( 1776,6,4,12,36,13,111)",
95 utc(1776,6,4,12,36,13,111) );
96 addNewTestCase( Date.UTC( 2525,9,18,15,30,1,123),
97 "Date.UTC( 2525,9,18,15,30,1,123)",
98 utc(2525,9,18,15,30,1,123) );
100 // Dates around 29 Feb 2000
102 addNewTestCase( Date.UTC( 2000,1,29,0,0,0,0 ),
103 "Date.UTC( 2000,1,29,0,0,0,0 )",
104 utc(2000,1,29,0,0,0,0) );
105 addNewTestCase( Date.UTC( 2000,1,29,8,0,0,0 ),
106 "Date.UTC( 2000,1,29,8,0,0,0 )",
107 utc(2000,1,29,8,0,0,0) );
109 // Dates around 1 Jan 2005
111 addNewTestCase( Date.UTC( 2005,0,1,0,0,0,0 ),
112 "Date.UTC( 2005,0,1,0,0,0,0 )",
113 utc(2005,0,1,0,0,0,0) );
114 addNewTestCase( Date.UTC( 2004,11,31,16,0,0,0 ),
115 "Date.UTC( 2004,11,31,16,0,0,0 )",
116 utc(2004,11,31,16,0,0,0) );
120 function addNewTestCase( DateCase, DateString, ExpectDate) {
123 new TestCase( SECTION, DateString, ExpectDate.value, DateCase );
124 new TestCase( SECTION, DateString, ExpectDate.value, DateCase );
137 function utc( year, month, date, hours, minutes, seconds, ms ) {
139 d.year = Number(year);
142 d.month = Number(month);
144 d.date = Number(date);
146 d.hours = Number(hours);
148 d.minutes = Number(minutes);
150 d.seconds = Number(seconds);
154 if ( isNaN(d.year) && 0 <= ToInteger(d.year) && d.year <= 99 ) {
155 d.year = 1900 + ToInteger(d.year);
158 if (isNaN(month) || isNaN(year) || isNaN(date) || isNaN(hours) ||
159 isNaN(minutes) || isNaN(seconds) || isNaN(ms) ) {
161 d.month = Number.NaN;
163 d.hours = Number.NaN;
164 d.minutes = Number.NaN;
165 d.seconds = Number.NaN;
167 d.value = Number.NaN;
173 d.day = MakeDay( d.year, d.month, d.date );
174 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
175 d.value = (TimeClip( MakeDate(d.day,d.time)));
180 function UTCTime( t ) {
181 sign = ( t < 0 ) ? -1 : 1;
182 return ( (t +(TZ_DIFF*msPerHour)) );