1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/shell.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,651 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/* 1.11 + * Date functions used by tests in Date suite 1.12 + * 1.13 + */ 1.14 +var msPerYear = 31536000000; 1.15 +var msPerDay = 86400000; 1.16 +var HoursPerDay = 24; 1.17 +var MinutesPerHour = 60; 1.18 +var SecondsPerMinute = 60; 1.19 +var msPerSecond = 1000; 1.20 +var msPerMinute = 60000; // msPerSecond * SecondsPerMinute 1.21 +var msPerHour = 3600000; // msPerMinute * MinutesPerHour 1.22 + 1.23 +var TZ_PST = -8; // offset of Pacific Standard Time from UTC 1.24 +var TZ_DIFF_RAW = GetRawTimezoneOffset(); // raw offset of tester's timezone from UTC 1.25 +var TZ_DIFF = GetTimezoneOffset(); // offset of tester's timezone from UTC 1.26 +var PST_DIFF_RAW = TZ_DIFF_RAW - TZ_PST; // raw offset of tester's timezone from PST 1.27 +var PST_DIFF = TZ_DIFF - TZ_PST; // offset of tester's timezone from PST 1.28 +var TZ_ADJUST = TZ_DIFF_RAW * msPerHour; 1.29 +var PST_ADJUST = TZ_PST * msPerHour; 1.30 + 1.31 +var DST_PERIOD = DaylightSavingPeriod(); // time period when DST is used 1.32 +var DST_1970 = DaylightSavingObserved(1970); // Was DST observed in 1970? 1.33 +var DST_1971 = DaylightSavingObserved(1971); // Was DST observed in 1971? 1.34 + 1.35 +var TIME_0000 = (function () 1.36 + { // calculate time for year 0 1.37 + for ( var time = 0, year = 1969; year >= 0; year-- ) { 1.38 + time -= TimeInYear(year); 1.39 + } 1.40 + return time; 1.41 + })(); 1.42 +var TIME_1970 = 0; 1.43 +var TIME_2000 = 946684800000; 1.44 +var TIME_1900 = -2208988800000; 1.45 +var UTC_FEB_29_2000 = TIME_2000 + 31*msPerDay + 28*msPerDay; 1.46 +var UTC_JAN_1_2005 = TIME_2000 + TimeInYear(2000) + TimeInYear(2001) + 1.47 + TimeInYear(2002) + TimeInYear(2003) + TimeInYear(2004); 1.48 +var now = new Date(); 1.49 +var TIME_NOW = now.valueOf(); //valueOf() is to accurate to the millisecond 1.50 + //Date.parse() is accurate only to the second 1.51 + 1.52 +/* 1.53 + * Originally, the test suite used a hard-coded value TZ_DIFF = -8. 1.54 + * But that was only valid for testers in the Pacific Standard Time Zone! 1.55 + * We calculate the proper number dynamically for any tester. We just 1.56 + * have to be careful not to use a date subject to Daylight Savings Time... 1.57 + */ 1.58 +function GetRawTimezoneOffset() 1.59 +{ 1.60 + var t1 = new Date(2000, 1, 1).getTimezoneOffset(); 1.61 + var t2 = new Date(2000, 1 + 6, 1).getTimezoneOffset(); 1.62 + if ((t1 - t2) >= 0) { 1.63 + // 1) timezone without daylight saving time 1.64 + // 2) northern hemisphere with daylight saving time 1.65 + return -t1 / MinutesPerHour; 1.66 + } else { 1.67 + // 3) southern hemisphere with daylight saving time 1.68 + return -t2 / MinutesPerHour; 1.69 + } 1.70 +} 1.71 + 1.72 +/* 1.73 + * Returns the timezone offset, possibly including daylight saving time. 1.74 + * (This function is only used to obtain the relative timezone offset to PST, 1.75 + * see TZ_DIFF and PST_DIFF in adjustResultArray().) 1.76 + */ 1.77 +function GetTimezoneOffset() 1.78 +{ 1.79 + return -(new Date(2000, 1, 1).getTimezoneOffset()) / MinutesPerHour; 1.80 +} 1.81 + 1.82 +/* 1.83 + * Determine when daylight saving time is used in the current timezone. 1.84 + */ 1.85 +function DaylightSavingPeriod() 1.86 +{ 1.87 + var t1 = new Date(2000, 1, 1).getTimezoneOffset(); 1.88 + var t2 = new Date(2000, 1 + 6, 1).getTimezoneOffset(); 1.89 + if (t1 == t2) { 1.90 + // timezone without daylight saving time 1.91 + return 0; 1.92 + } else if ((t1 - t2) > 0) { 1.93 + // northern hemisphere with daylight saving time 1.94 + return 1; 1.95 + } else { 1.96 + // southern hemisphere with daylight saving time 1.97 + return -1; 1.98 + } 1.99 +} 1.100 + 1.101 +/* 1.102 + * Test whether daylight time saving was observed in the supplied year 1.103 + */ 1.104 +function DaylightSavingObserved(y) 1.105 +{ 1.106 + var t1 = new Date(y, 1, 1).getTimezoneOffset(); 1.107 + var t2 = new Date(y, 1 + 6, 1).getTimezoneOffset(); 1.108 + return (t1 != t2); 1.109 +} 1.110 + 1.111 +/* 1.112 + * Don't apply DST near start of epoch unless absolutely necessary 1.113 + */ 1.114 +function IgnoreDaylightSaving(t) 1.115 +{ 1.116 + if ((0 <= t && t < msPerYear) && !DST_1970) { 1.117 + return true; 1.118 + } 1.119 + if ((msPerYear <= t && t < 2*msPerYear) && !DST_1971) { 1.120 + return true; 1.121 + } 1.122 + return false; 1.123 +} 1.124 + 1.125 +/* 1.126 + * Date test "ResultArrays" are hard-coded for Pacific Standard Time. 1.127 + * We must adjust them for the tester's own timezone - 1.128 + */ 1.129 +function adjustResultArray(ResultArray, msMode) 1.130 +{ 1.131 + // If the tester's system clock is in PST, no need to continue - 1.132 +// if (!PST_DIFF) {return;} 1.133 + 1.134 + /* The date testcases instantiate Date objects in two different ways: 1.135 + * 1.136 + * millisecond mode: e.g. dt = new Date(10000000); 1.137 + * year-month-day mode: dt = new Date(2000, 5, 1, ...); 1.138 + * 1.139 + * In the first case, the date is measured from Time 0 in Greenwich (i.e. UTC). 1.140 + * In the second case, it is measured with reference to the tester's local timezone. 1.141 + * 1.142 + * In the first case we must correct those values expected for local measurements, 1.143 + * like dt.getHours() etc. No correction is necessary for dt.getUTCHours() etc. 1.144 + * 1.145 + * In the second case, it is exactly the other way around - 1.146 + */ 1.147 + if (msMode) 1.148 + { 1.149 + // The hard-coded UTC milliseconds from Time 0 derives from a UTC date. 1.150 + // Shift to the right by the offset between UTC and the tester. 1.151 + if (IgnoreDaylightSaving(ResultArray[TIME])) { 1.152 + var t = ResultArray[TIME] + TZ_DIFF_RAW*msPerHour; 1.153 + } else { 1.154 + var t = ResultArray[TIME] + TZ_DIFF*msPerHour; 1.155 + } 1.156 + 1.157 + // Use our date arithmetic functions to determine the local hour, day, etc. 1.158 + ResultArray[HOURS] = HourFromTime(t); 1.159 + ResultArray[DAY] = WeekDay(t); 1.160 + ResultArray[DATE] = DateFromTime(t); 1.161 + ResultArray[MONTH] = MonthFromTime(t); 1.162 + ResultArray[YEAR] = YearFromTime(t); 1.163 + } 1.164 + else 1.165 + { 1.166 + // The hard-coded UTC milliseconds from Time 0 derives from a PST date. 1.167 + // Shift to the left by the offset between PST and the tester. 1.168 + var t = ResultArray[TIME] - PST_DIFF*msPerHour; 1.169 + 1.170 + // Use our date arithmetic functions to determine the UTC hour, day, etc. 1.171 + ResultArray[TIME] = t; 1.172 + ResultArray[UTC_HOURS] = HourFromTime(t); 1.173 + ResultArray[UTC_DAY] = WeekDay(t); 1.174 + ResultArray[UTC_DATE] = DateFromTime(t); 1.175 + ResultArray[UTC_MONTH] = MonthFromTime(t); 1.176 + ResultArray[UTC_YEAR] = YearFromTime(t); 1.177 + } 1.178 +} 1.179 + 1.180 +function Day( t ) { 1.181 + return ( Math.floor(t/msPerDay ) ); 1.182 +} 1.183 +function DaysInYear( y ) { 1.184 + if ( y % 4 != 0 ) { 1.185 + return 365; 1.186 + } 1.187 + if ( (y % 4 == 0) && (y % 100 != 0) ) { 1.188 + return 366; 1.189 + } 1.190 + if ( (y % 100 == 0) && (y % 400 != 0) ) { 1.191 + return 365; 1.192 + } 1.193 + if ( (y % 400 == 0) ){ 1.194 + return 366; 1.195 + } else { 1.196 + return "ERROR: DaysInYear(" + y + ") case not covered"; 1.197 + } 1.198 +} 1.199 +function TimeInYear( y ) { 1.200 + return ( DaysInYear(y) * msPerDay ); 1.201 +} 1.202 +function DayNumber( t ) { 1.203 + return ( Math.floor( t / msPerDay ) ); 1.204 +} 1.205 +function TimeWithinDay( t ) { 1.206 + 1.207 + var r = t % msPerDay; 1.208 + 1.209 + if (r < 0) 1.210 + { 1.211 + r += msPerDay; 1.212 + } 1.213 + return r; 1.214 + 1.215 +} 1.216 +function YearNumber( t ) { 1.217 +} 1.218 +function TimeFromYear( y ) { 1.219 + return ( msPerDay * DayFromYear(y) ); 1.220 +} 1.221 +function DayFromYear( y ) { 1.222 + return ( 365*(y-1970) + 1.223 + Math.floor((y-1969)/4) - 1.224 + Math.floor((y-1901)/100) + 1.225 + Math.floor((y-1601)/400) ); 1.226 +} 1.227 +function InLeapYear( t ) { 1.228 + if ( DaysInYear(YearFromTime(t)) == 365 ) { 1.229 + return 0; 1.230 + } 1.231 + if ( DaysInYear(YearFromTime(t)) == 366 ) { 1.232 + return 1; 1.233 + } else { 1.234 + return "ERROR: InLeapYear("+ t + ") case not covered"; 1.235 + } 1.236 +} 1.237 +function YearFromTime( t ) { 1.238 + t = Number( t ); 1.239 + var sign = ( t < 0 ) ? -1 : 1; 1.240 + var year = ( sign < 0 ) ? 1969 : 1970; 1.241 + for ( var timeToTimeZero = t; ; ) { 1.242 + // subtract the current year's time from the time that's left. 1.243 + timeToTimeZero -= sign * TimeInYear(year) 1.244 + 1.245 + // if there's less than the current year's worth of time left, then break. 1.246 + if ( sign < 0 ) { 1.247 + if ( sign * timeToTimeZero <= 0 ) { 1.248 + break; 1.249 + } else { 1.250 + year += sign; 1.251 + } 1.252 + } else { 1.253 + if ( sign * timeToTimeZero < 0 ) { 1.254 + break; 1.255 + } else { 1.256 + year += sign; 1.257 + } 1.258 + } 1.259 + } 1.260 + return ( year ); 1.261 +} 1.262 +function MonthFromTime( t ) { 1.263 + // i know i could use switch but i'd rather not until it's part of ECMA 1.264 + var day = DayWithinYear( t ); 1.265 + var leap = InLeapYear(t); 1.266 + 1.267 + if ( (0 <= day) && (day < 31) ) { 1.268 + return 0; 1.269 + } 1.270 + if ( (31 <= day) && (day < (59+leap)) ) { 1.271 + return 1; 1.272 + } 1.273 + if ( ((59+leap) <= day) && (day < (90+leap)) ) { 1.274 + return 2; 1.275 + } 1.276 + if ( ((90+leap) <= day) && (day < (120+leap)) ) { 1.277 + return 3; 1.278 + } 1.279 + if ( ((120+leap) <= day) && (day < (151+leap)) ) { 1.280 + return 4; 1.281 + } 1.282 + if ( ((151+leap) <= day) && (day < (181+leap)) ) { 1.283 + return 5; 1.284 + } 1.285 + if ( ((181+leap) <= day) && (day < (212+leap)) ) { 1.286 + return 6; 1.287 + } 1.288 + if ( ((212+leap) <= day) && (day < (243+leap)) ) { 1.289 + return 7; 1.290 + } 1.291 + if ( ((243+leap) <= day) && (day < (273+leap)) ) { 1.292 + return 8; 1.293 + } 1.294 + if ( ((273+leap) <= day) && (day < (304+leap)) ) { 1.295 + return 9; 1.296 + } 1.297 + if ( ((304+leap) <= day) && (day < (334+leap)) ) { 1.298 + return 10; 1.299 + } 1.300 + if ( ((334+leap) <= day) && (day < (365+leap)) ) { 1.301 + return 11; 1.302 + } else { 1.303 + return "ERROR: MonthFromTime("+t+") not known"; 1.304 + } 1.305 +} 1.306 +function DayWithinYear( t ) { 1.307 + return( Day(t) - DayFromYear(YearFromTime(t))); 1.308 +} 1.309 +function DateFromTime( t ) { 1.310 + var day = DayWithinYear(t); 1.311 + var month = MonthFromTime(t); 1.312 + 1.313 + if ( month == 0 ) { 1.314 + return ( day + 1 ); 1.315 + } 1.316 + if ( month == 1 ) { 1.317 + return ( day - 30 ); 1.318 + } 1.319 + if ( month == 2 ) { 1.320 + return ( day - 58 - InLeapYear(t) ); 1.321 + } 1.322 + if ( month == 3 ) { 1.323 + return ( day - 89 - InLeapYear(t)); 1.324 + } 1.325 + if ( month == 4 ) { 1.326 + return ( day - 119 - InLeapYear(t)); 1.327 + } 1.328 + if ( month == 5 ) { 1.329 + return ( day - 150- InLeapYear(t)); 1.330 + } 1.331 + if ( month == 6 ) { 1.332 + return ( day - 180- InLeapYear(t)); 1.333 + } 1.334 + if ( month == 7 ) { 1.335 + return ( day - 211- InLeapYear(t)); 1.336 + } 1.337 + if ( month == 8 ) { 1.338 + return ( day - 242- InLeapYear(t)); 1.339 + } 1.340 + if ( month == 9 ) { 1.341 + return ( day - 272- InLeapYear(t)); 1.342 + } 1.343 + if ( month == 10 ) { 1.344 + return ( day - 303- InLeapYear(t)); 1.345 + } 1.346 + if ( month == 11 ) { 1.347 + return ( day - 333- InLeapYear(t)); 1.348 + } 1.349 + 1.350 + return ("ERROR: DateFromTime("+t+") not known" ); 1.351 +} 1.352 +function WeekDay( t ) { 1.353 + var weekday = (Day(t)+4) % 7; 1.354 + return( weekday < 0 ? 7 + weekday : weekday ); 1.355 +} 1.356 + 1.357 +// missing daylight savings time adjustment 1.358 + 1.359 +function HourFromTime( t ) { 1.360 + var h = Math.floor( t / msPerHour ) % HoursPerDay; 1.361 + return ( (h<0) ? HoursPerDay + h : h ); 1.362 +} 1.363 +function MinFromTime( t ) { 1.364 + var min = Math.floor( t / msPerMinute ) % MinutesPerHour; 1.365 + return( ( min < 0 ) ? MinutesPerHour + min : min ); 1.366 +} 1.367 +function SecFromTime( t ) { 1.368 + var sec = Math.floor( t / msPerSecond ) % SecondsPerMinute; 1.369 + return ( (sec < 0 ) ? SecondsPerMinute + sec : sec ); 1.370 +} 1.371 +function msFromTime( t ) { 1.372 + var ms = t % msPerSecond; 1.373 + return ( (ms < 0 ) ? msPerSecond + ms : ms ); 1.374 +} 1.375 +function LocalTZA() { 1.376 + return ( TZ_DIFF_RAW * msPerHour ); 1.377 +} 1.378 +function UTC( t ) { 1.379 + return ( t - LocalTZA() - DaylightSavingTA(t - LocalTZA()) ); 1.380 +} 1.381 +function LocalTime( t ) { 1.382 + return ( t + LocalTZA() + DaylightSavingTA(t) ); 1.383 +} 1.384 +function DaylightSavingTA( t ) { 1.385 + if (IgnoreDaylightSaving(t)) { 1.386 + return 0; 1.387 + } 1.388 + 1.389 + if (DST_PERIOD > 0) { 1.390 + // northern hemisphere 1.391 + var dst_start = GetDSTStart(t); 1.392 + var dst_end = GetDSTEnd(t); 1.393 + 1.394 + if ( t >= dst_start && t < dst_end ) 1.395 + return msPerHour; 1.396 + } else if (DST_PERIOD < 0) { 1.397 + // southern hemisphere 1.398 + var dst_start = GetDSTStart_Southern(t); 1.399 + var dst_end = GetDSTEnd_Southern(t); 1.400 + 1.401 + if ( t >= dst_start && t < GetDSTEnd_Southern(t + msPerYear) ) 1.402 + return msPerHour; 1.403 + if ( t < dst_end && t >= GetDSTEnd_Southern(t - msPerYear) ) 1.404 + return msPerHour; 1.405 + } 1.406 + 1.407 + return 0; 1.408 +} 1.409 + 1.410 +function GetFirstSundayInMonth( t, m ) { 1.411 + var year = YearFromTime(t); 1.412 + var leap = InLeapYear(t); 1.413 + 1.414 +// month m 0..11 1.415 +// april == 3 1.416 +// march == 2 1.417 + 1.418 + // set time to first day of month m 1.419 + var time = TimeFromYear(year); 1.420 + for (var i = 0; i < m; ++i) 1.421 + { 1.422 + time += TimeInMonth(i, leap); 1.423 + } 1.424 + 1.425 + for ( var first_sunday = time; WeekDay(first_sunday) > 0; 1.426 + first_sunday += msPerDay ) 1.427 + { 1.428 + ; 1.429 + } 1.430 + 1.431 + return first_sunday; 1.432 +} 1.433 + 1.434 +function GetLastSundayInMonth( t, m ) { 1.435 + var year = YearFromTime(t); 1.436 + var leap = InLeapYear(t); 1.437 + 1.438 +// month m 0..11 1.439 +// april == 3 1.440 +// march == 2 1.441 + 1.442 + // first day of following month 1.443 + var time = TimeFromYear(year); 1.444 + for (var i = 0; i <= m; ++i) 1.445 + { 1.446 + time += TimeInMonth(i, leap); 1.447 + } 1.448 + // prev day == last day of month 1.449 + time -= msPerDay; 1.450 + 1.451 + for ( var last_sunday = time; WeekDay(last_sunday) > 0; 1.452 + last_sunday -= msPerDay ) 1.453 + { 1.454 + ; 1.455 + } 1.456 + return last_sunday; 1.457 +} 1.458 + 1.459 +/* 1.460 + 15.9.1.9 Daylight Saving Time Adjustment 1.461 + 1.462 + The implementation of ECMAScript should not try to determine whether 1.463 + the exact time was subject to daylight saving time, but just whether 1.464 + daylight saving time would have been in effect if the current 1.465 + daylight saving time algorithm had been used at the time. This avoids 1.466 + complications such as taking into account the years that the locale 1.467 + observed daylight saving time year round. 1.468 +*/ 1.469 + 1.470 +/* 1.471 + US DST algorithm 1.472 + 1.473 + Before 2007, DST starts first Sunday in April at 2 AM and ends last 1.474 + Sunday in October at 2 AM 1.475 + 1.476 + Starting in 2007, DST starts second Sunday in March at 2 AM and ends 1.477 + first Sunday in November at 2 AM 1.478 + 1.479 + Note that different operating systems behave differently. 1.480 + 1.481 + Fully patched Windows XP uses the 2007 algorithm for all dates while 1.482 + fully patched Fedora Core 6 and RHEL 4 Linux use the algorithm in 1.483 + effect at the time. 1.484 + 1.485 + Since pre-2007 DST is a subset of 2007 DST rules, this only affects 1.486 + tests that occur in the period Mar-Apr and Oct-Nov where the two 1.487 + algorithms do not agree. 1.488 + 1.489 +*/ 1.490 + 1.491 +function GetDSTStart( t ) 1.492 +{ 1.493 + return (GetFirstSundayInMonth(t, 2) + 7*msPerDay + 2*msPerHour - LocalTZA()); 1.494 +} 1.495 + 1.496 +function GetDSTEnd( t ) 1.497 +{ 1.498 + return (GetFirstSundayInMonth(t, 10) + 2*msPerHour - LocalTZA()); 1.499 +} 1.500 + 1.501 +function GetOldDSTStart( t ) 1.502 +{ 1.503 + return (GetFirstSundayInMonth(t, 3) + 2*msPerHour - LocalTZA()); 1.504 +} 1.505 + 1.506 +function GetOldDSTEnd( t ) 1.507 +{ 1.508 + return (GetLastSundayInMonth(t, 9) + 2*msPerHour - LocalTZA()); 1.509 +} 1.510 + 1.511 +/* 1.512 + * Daylight saving time start/end date for 'Australia' 1.513 + * (arbitrarily chosen as a representative for the southern hemisphere) 1.514 + */ 1.515 + 1.516 +function GetDSTStart_Southern( t ) 1.517 +{ 1.518 + return (GetFirstSundayInMonth(t, 9) + 2*msPerHour - LocalTZA()); 1.519 +} 1.520 + 1.521 +function GetDSTEnd_Southern( t ) 1.522 +{ 1.523 + return (GetFirstSundayInMonth(t, 3) + 2*msPerHour - LocalTZA()); 1.524 +} 1.525 + 1.526 +function MakeTime( hour, min, sec, ms ) { 1.527 + if ( isNaN( hour ) || isNaN( min ) || isNaN( sec ) || isNaN( ms ) ) { 1.528 + return Number.NaN; 1.529 + } 1.530 + 1.531 + hour = ToInteger(hour); 1.532 + min = ToInteger( min); 1.533 + sec = ToInteger( sec); 1.534 + ms = ToInteger( ms ); 1.535 + 1.536 + return( (hour*msPerHour) + (min*msPerMinute) + 1.537 + (sec*msPerSecond) + ms ); 1.538 +} 1.539 +function MakeDay( year, month, date ) { 1.540 + if ( isNaN(year) || isNaN(month) || isNaN(date) ) { 1.541 + return Number.NaN; 1.542 + } 1.543 + year = ToInteger(year); 1.544 + month = ToInteger(month); 1.545 + date = ToInteger(date ); 1.546 + 1.547 + var sign = ( year < 1970 ) ? -1 : 1; 1.548 + var t = ( year < 1970 ) ? 1 : 0; 1.549 + var y = ( year < 1970 ) ? 1969 : 1970; 1.550 + 1.551 + var result5 = year + Math.floor( month/12 ); 1.552 + var result6 = month % 12; 1.553 + 1.554 + if ( year < 1970 ) { 1.555 + for ( y = 1969; y >= year; y += sign ) { 1.556 + t += sign * TimeInYear(y); 1.557 + } 1.558 + } else { 1.559 + for ( y = 1970 ; y < year; y += sign ) { 1.560 + t += sign * TimeInYear(y); 1.561 + } 1.562 + } 1.563 + 1.564 + var leap = InLeapYear( t ); 1.565 + 1.566 + for ( var m = 0; m < month; m++ ) { 1.567 + t += TimeInMonth( m, leap ); 1.568 + } 1.569 + 1.570 + if ( YearFromTime(t) != result5 ) { 1.571 + return Number.NaN; 1.572 + } 1.573 + if ( MonthFromTime(t) != result6 ) { 1.574 + return Number.NaN; 1.575 + } 1.576 + if ( DateFromTime(t) != 1 ) { 1.577 + return Number.NaN; 1.578 + } 1.579 + 1.580 + return ( (Day(t)) + date - 1 ); 1.581 +} 1.582 +function TimeInMonth( month, leap ) { 1.583 + // september april june november 1.584 + // jan 0 feb 1 mar 2 apr 3 may 4 june 5 jul 6 1.585 + // aug 7 sep 8 oct 9 nov 10 dec 11 1.586 + 1.587 + if ( month == 3 || month == 5 || month == 8 || month == 10 ) { 1.588 + return ( 30*msPerDay ); 1.589 + } 1.590 + 1.591 + // all the rest 1.592 + if ( month == 0 || month == 2 || month == 4 || month == 6 || 1.593 + month == 7 || month == 9 || month == 11 ) { 1.594 + return ( 31*msPerDay ); 1.595 + } 1.596 + 1.597 + // save february 1.598 + return ( (leap == 0) ? 28*msPerDay : 29*msPerDay ); 1.599 +} 1.600 +function MakeDate( day, time ) { 1.601 + if ( day == Number.POSITIVE_INFINITY || 1.602 + day == Number.NEGATIVE_INFINITY ) { 1.603 + return Number.NaN; 1.604 + } 1.605 + if ( time == Number.POSITIVE_INFINITY || 1.606 + time == Number.NEGATIVE_INFINITY ) { 1.607 + return Number.NaN; 1.608 + } 1.609 + return ( day * msPerDay ) + time; 1.610 +} 1.611 +function TimeClip( t ) { 1.612 + if ( isNaN( t ) ) { 1.613 + return ( Number.NaN ); 1.614 + } 1.615 + if ( Math.abs( t ) > 8.64e15 ) { 1.616 + return ( Number.NaN ); 1.617 + } 1.618 + 1.619 + return ( ToInteger( t ) ); 1.620 +} 1.621 +function ToInteger( t ) { 1.622 + t = Number( t ); 1.623 + 1.624 + if ( isNaN( t ) ){ 1.625 + return ( Number.NaN ); 1.626 + } 1.627 + if ( t == 0 || t == -0 || 1.628 + t == Number.POSITIVE_INFINITY || t == Number.NEGATIVE_INFINITY ) { 1.629 + return 0; 1.630 + } 1.631 + 1.632 + var sign = ( t < 0 ) ? -1 : 1; 1.633 + 1.634 + return ( sign * Math.floor( Math.abs( t ) ) ); 1.635 +} 1.636 +function Enumerate ( o ) { 1.637 + var p; 1.638 + for ( p in o ) { 1.639 + print( p +": " + o[p] ); 1.640 + } 1.641 +} 1.642 + 1.643 +/* these functions are useful for running tests manually in Rhino */ 1.644 + 1.645 +function GetContext() { 1.646 + return Packages.com.netscape.javascript.Context.getCurrentContext(); 1.647 +} 1.648 +function OptLevel( i ) { 1.649 + i = Number(i); 1.650 + var cx = GetContext(); 1.651 + cx.setOptimizationLevel(i); 1.652 +} 1.653 +/* end of Rhino functions */ 1.654 +