| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
var completed = false; |
| 6 |
var testcases; |
| 7 |
var tc = 0; |
| 8 |
|
| 9 |
SECTION = ""; |
| 10 |
VERSION = ""; |
| 11 |
BUGNUMBER = ""; |
| 12 |
TITLE = ""; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
var GLOBAL = "[object global]"; |
| 18 |
var PASSED = " PASSED!" |
| 19 |
var FAILED = " FAILED! expected: "; |
| 20 |
var DEBUG = false; |
| 21 |
|
| 22 |
TZ_DIFF = -8; |
| 23 |
|
| 24 |
var TT = ""; |
| 25 |
var TT_ = ""; |
| 26 |
var BR = ""; |
| 27 |
var NBSP = " "; |
| 28 |
var CR = "\n"; |
| 29 |
var FONT = ""; |
| 30 |
var FONT_ = ""; |
| 31 |
var FONT_RED = ""; |
| 32 |
var FONT_GREEN = ""; |
| 33 |
var B = ""; |
| 34 |
var B_ = "" |
| 35 |
var H2 = ""; |
| 36 |
var H2_ = ""; |
| 37 |
var HR = ""; |
| 38 |
var DEBUG = false; |
| 39 |
|
| 40 |
var PASSED = " PASSED!" |
| 41 |
var FAILED = " FAILED! expected: "; |
| 42 |
|
| 43 |
function test() { |
| 44 |
for ( tc=0; tc < testcases.length; tc++ ) { |
| 45 |
testcases[tc].passed = writeTestCaseResult( |
| 46 |
testcases[tc].expect, |
| 47 |
testcases[tc].actual, |
| 48 |
testcases[tc].description +" = "+ |
| 49 |
testcases[tc].actual ); |
| 50 |
|
| 51 |
testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; |
| 52 |
} |
| 53 |
stopTest(); |
| 54 |
return ( testcases ); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
function AddTestCase( description, expect, actual ) { |
| 61 |
testcases[tc++] = new TestCase( SECTION, description, expect, actual ); |
| 62 |
} |
| 63 |
|
| 64 |
function TestCase( n, d, e, a ) { |
| 65 |
this.name = n; |
| 66 |
this.description = d; |
| 67 |
this.expect = e; |
| 68 |
this.actual = a; |
| 69 |
this.passed = true; |
| 70 |
this.reason = ""; |
| 71 |
this.bugnumber = BUGNUMBER; |
| 72 |
|
| 73 |
this.passed = getTestCaseResult( this.expect, this.actual ); |
| 74 |
if ( DEBUG ) { |
| 75 |
print( "added " + this.description ); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
function startTest() { |
| 84 |
if ( version ) { |
| 85 |
|
| 86 |
if ( VERSION == "ECMA_1" ) { |
| 87 |
version ( "130" ); |
| 88 |
} |
| 89 |
if ( VERSION == "JS_1.3" ) { |
| 90 |
version ( "130" ); |
| 91 |
} |
| 92 |
if ( VERSION == "JS_1.2" ) { |
| 93 |
version ( "120" ); |
| 94 |
} |
| 95 |
if ( VERSION == "JS_1.1" ) { |
| 96 |
version ( "110" ); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
if ( BUGNUMBER ) { |
| 105 |
print ("BUGNUMBER: " + BUGNUMBER ); |
| 106 |
} |
| 107 |
|
| 108 |
testcases = new Array(); |
| 109 |
tc = 0; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
function test() { |
| 114 |
for ( tc=0; tc < testcases.length; tc++ ) { |
| 115 |
testcases[tc].passed = writeTestCaseResult( |
| 116 |
testcases[tc].expect, |
| 117 |
testcases[tc].actual, |
| 118 |
testcases[tc].description +" = "+ testcases[tc].actual ); |
| 119 |
testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; |
| 120 |
} |
| 121 |
stopTest(); |
| 122 |
return ( testcases ); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
function getTestCaseResult( expect, actual ) { |
| 127 |
|
| 128 |
|
| 129 |
if ( actual != actual ) { |
| 130 |
if ( typeof actual == "object" ) { |
| 131 |
actual = "NaN object"; |
| 132 |
} else { |
| 133 |
actual = "NaN number"; |
| 134 |
} |
| 135 |
} |
| 136 |
if ( expect != expect ) { |
| 137 |
if ( typeof expect == "object" ) { |
| 138 |
expect = "NaN object"; |
| 139 |
} else { |
| 140 |
expect = "NaN number"; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
var passed = ( expect == actual ) ? true : false; |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
if ( !passed |
| 149 |
&& typeof(actual) == "number" |
| 150 |
&& typeof(expect) == "number" |
| 151 |
) { |
| 152 |
if ( Math.abs(actual-expect) < 0.0000001 ) { |
| 153 |
passed = true; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
if ( typeof(expect) != typeof(actual) ) { |
| 159 |
passed = false; |
| 160 |
} |
| 161 |
|
| 162 |
return passed; |
| 163 |
} |
| 164 |
function writeTestCaseResult( expect, actual, string ) { |
| 165 |
var passed = getTestCaseResult( expect, actual ); |
| 166 |
writeFormattedResult( expect, actual, string, passed ); |
| 167 |
return passed; |
| 168 |
} |
| 169 |
function writeFormattedResult( expect, actual, string, passed ) { |
| 170 |
var s = TT + string ; |
| 171 |
|
| 172 |
for ( k = 0; |
| 173 |
k < (60 - string.length >= 0 ? 60 - string.length : 5) ; |
| 174 |
k++ ) { |
| 175 |
} |
| 176 |
|
| 177 |
s += B ; |
| 178 |
s += ( passed ) ? FONT_GREEN + NBSP + PASSED : FONT_RED + NBSP + FAILED + expect + TT_ ; |
| 179 |
|
| 180 |
print( s + FONT_ + B_ + TT_ ); |
| 181 |
|
| 182 |
return passed; |
| 183 |
} |
| 184 |
|
| 185 |
function writeHeaderToLog( string ) { |
| 186 |
print( H2 + string + H2_ ); |
| 187 |
} |
| 188 |
function stopTest() |
| 189 |
{ |
| 190 |
var sizeTag = "<#TEST CASES SIZE>"; |
| 191 |
var doneTag = "<#TEST CASES DONE>"; |
| 192 |
var beginTag = "<#TEST CASE "; |
| 193 |
var endTag = ">"; |
| 194 |
|
| 195 |
print(sizeTag); |
| 196 |
print(testcases.length); |
| 197 |
for (tc = 0; tc < testcases.length; tc++) |
| 198 |
{ |
| 199 |
print(beginTag + 'PASSED' + endTag); |
| 200 |
print(testcases[tc].passed); |
| 201 |
print(beginTag + 'NAME' + endTag); |
| 202 |
print(testcases[tc].name); |
| 203 |
print(beginTag + 'EXPECTED' + endTag); |
| 204 |
print(testcases[tc].expect); |
| 205 |
print(beginTag + 'ACTUAL' + endTag); |
| 206 |
print(testcases[tc].actual); |
| 207 |
print(beginTag + 'DESCRIPTION' + endTag); |
| 208 |
print(testcases[tc].description); |
| 209 |
print(beginTag + 'REASON' + endTag); |
| 210 |
print(( testcases[tc].passed ) ? "" : "wrong value "); |
| 211 |
print(beginTag + 'BUGNUMBER' + endTag); |
| 212 |
print( BUGNUMBER ); |
| 213 |
} |
| 214 |
print(doneTag); |
| 215 |
print( HR ); |
| 216 |
gc(); |
| 217 |
} |
| 218 |
function getFailedCases() { |
| 219 |
for ( var i = 0; i < testcases.length; i++ ) { |
| 220 |
if ( ! testcases[i].passed ) { |
| 221 |
print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect ); |
| 222 |
} |
| 223 |
} |
| 224 |
} |
| 225 |
function err( msg, page, line ) { |
| 226 |
testcases[tc].actual = "error"; |
| 227 |
testcases[tc].reason = msg; |
| 228 |
writeTestCaseResult( testcases[tc].expect, |
| 229 |
testcases[tc].actual, |
| 230 |
testcases[tc].description +" = "+ testcases[tc].actual + |
| 231 |
": " + testcases[tc].reason ); |
| 232 |
stopTest(); |
| 233 |
return true; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
var msPerDay = 86400000; |
| 248 |
var HoursPerDay = 24; |
| 249 |
var MinutesPerHour = 60; |
| 250 |
var SecondsPerMinute = 60; |
| 251 |
var msPerSecond = 1000; |
| 252 |
var msPerMinute = 60000; |
| 253 |
var msPerHour = 3600000; |
| 254 |
|
| 255 |
var TIME_1970 = 0; |
| 256 |
var TIME_2000 = 946684800000; |
| 257 |
var TIME_1900 = -2208988800000; |
| 258 |
|
| 259 |
function Day( t ) { |
| 260 |
return ( Math.floor(t/msPerDay ) ); |
| 261 |
} |
| 262 |
function DaysInYear( y ) { |
| 263 |
if ( y % 4 != 0 ) { |
| 264 |
return 365; |
| 265 |
} |
| 266 |
if ( (y % 4 == 0) && (y % 100 != 0) ) { |
| 267 |
return 366; |
| 268 |
} |
| 269 |
if ( (y % 100 == 0) && (y % 400 != 0) ) { |
| 270 |
return 365; |
| 271 |
} |
| 272 |
if ( (y % 400 == 0) ){ |
| 273 |
return 366; |
| 274 |
} else { |
| 275 |
return "ERROR: DaysInYear(" + y + ") case not covered"; |
| 276 |
} |
| 277 |
} |
| 278 |
function TimeInYear( y ) { |
| 279 |
return ( DaysInYear(y) * msPerDay ); |
| 280 |
} |
| 281 |
function DayNumber( t ) { |
| 282 |
return ( Math.floor( t / msPerDay ) ); |
| 283 |
} |
| 284 |
function TimeWithinDay( t ) { |
| 285 |
if ( t < 0 ) { |
| 286 |
return ( (t % msPerDay) + msPerDay ); |
| 287 |
} else { |
| 288 |
return ( t % msPerDay ); |
| 289 |
} |
| 290 |
} |
| 291 |
function YearNumber( t ) { |
| 292 |
} |
| 293 |
function TimeFromYear( y ) { |
| 294 |
return ( msPerDay * DayFromYear(y) ); |
| 295 |
} |
| 296 |
function DayFromYear( y ) { |
| 297 |
return ( 365*(y-1970) + |
| 298 |
Math.floor((y-1969)/4) - |
| 299 |
Math.floor((y-1901)/100) + |
| 300 |
Math.floor((y-1601)/400) ); |
| 301 |
} |
| 302 |
function InLeapYear( t ) { |
| 303 |
if ( DaysInYear(YearFromTime(t)) == 365 ) { |
| 304 |
return 0; |
| 305 |
} |
| 306 |
if ( DaysInYear(YearFromTime(t)) == 366 ) { |
| 307 |
return 1; |
| 308 |
} else { |
| 309 |
return "ERROR: InLeapYear("+t+") case not covered"; |
| 310 |
} |
| 311 |
} |
| 312 |
function YearFromTime( t ) { |
| 313 |
t = Number( t ); |
| 314 |
var sign = ( t < 0 ) ? -1 : 1; |
| 315 |
var year = ( sign < 0 ) ? 1969 : 1970; |
| 316 |
for ( var timeToTimeZero = t; ; ) { |
| 317 |
|
| 318 |
timeToTimeZero -= sign * TimeInYear(year) |
| 319 |
|
| 320 |
|
| 321 |
if ( sign < 0 ) { |
| 322 |
if ( sign * timeToTimeZero <= 0 ) { |
| 323 |
break; |
| 324 |
} else { |
| 325 |
year += sign; |
| 326 |
} |
| 327 |
} else { |
| 328 |
if ( sign * timeToTimeZero < 0 ) { |
| 329 |
break; |
| 330 |
} else { |
| 331 |
year += sign; |
| 332 |
} |
| 333 |
} |
| 334 |
} |
| 335 |
return ( year ); |
| 336 |
} |
| 337 |
function MonthFromTime( t ) { |
| 338 |
|
| 339 |
var day = DayWithinYear( t ); |
| 340 |
var leap = InLeapYear(t); |
| 341 |
|
| 342 |
if ( (0 <= day) && (day < 31) ) { |
| 343 |
return 0; |
| 344 |
} |
| 345 |
if ( (31 <= day) && (day < (59+leap)) ) { |
| 346 |
return 1; |
| 347 |
} |
| 348 |
if ( ((59+leap) <= day) && (day < (90+leap)) ) { |
| 349 |
return 2; |
| 350 |
} |
| 351 |
if ( ((90+leap) <= day) && (day < (120+leap)) ) { |
| 352 |
return 3; |
| 353 |
} |
| 354 |
if ( ((120+leap) <= day) && (day < (151+leap)) ) { |
| 355 |
return 4; |
| 356 |
} |
| 357 |
if ( ((151+leap) <= day) && (day < (181+leap)) ) { |
| 358 |
return 5; |
| 359 |
} |
| 360 |
if ( ((181+leap) <= day) && (day < (212+leap)) ) { |
| 361 |
return 6; |
| 362 |
} |
| 363 |
if ( ((212+leap) <= day) && (day < (243+leap)) ) { |
| 364 |
return 7; |
| 365 |
} |
| 366 |
if ( ((243+leap) <= day) && (day < (273+leap)) ) { |
| 367 |
return 8; |
| 368 |
} |
| 369 |
if ( ((273+leap) <= day) && (day < (304+leap)) ) { |
| 370 |
return 9; |
| 371 |
} |
| 372 |
if ( ((304+leap) <= day) && (day < (334+leap)) ) { |
| 373 |
return 10; |
| 374 |
} |
| 375 |
if ( ((334+leap) <= day) && (day < (365+leap)) ) { |
| 376 |
return 11; |
| 377 |
} else { |
| 378 |
return "ERROR: MonthFromTime("+t+") not known"; |
| 379 |
} |
| 380 |
} |
| 381 |
function DayWithinYear( t ) { |
| 382 |
return( Day(t) - DayFromYear(YearFromTime(t))); |
| 383 |
} |
| 384 |
function DateFromTime( t ) { |
| 385 |
var day = DayWithinYear(t); |
| 386 |
var month = MonthFromTime(t); |
| 387 |
|
| 388 |
if ( month == 0 ) { |
| 389 |
return ( day + 1 ); |
| 390 |
} |
| 391 |
if ( month == 1 ) { |
| 392 |
return ( day - 30 ); |
| 393 |
} |
| 394 |
if ( month == 2 ) { |
| 395 |
return ( day - 58 - InLeapYear(t) ); |
| 396 |
} |
| 397 |
if ( month == 3 ) { |
| 398 |
return ( day - 89 - InLeapYear(t)); |
| 399 |
} |
| 400 |
if ( month == 4 ) { |
| 401 |
return ( day - 119 - InLeapYear(t)); |
| 402 |
} |
| 403 |
if ( month == 5 ) { |
| 404 |
return ( day - 150- InLeapYear(t)); |
| 405 |
} |
| 406 |
if ( month == 6 ) { |
| 407 |
return ( day - 180- InLeapYear(t)); |
| 408 |
} |
| 409 |
if ( month == 7 ) { |
| 410 |
return ( day - 211- InLeapYear(t)); |
| 411 |
} |
| 412 |
if ( month == 8 ) { |
| 413 |
return ( day - 242- InLeapYear(t)); |
| 414 |
} |
| 415 |
if ( month == 9 ) { |
| 416 |
return ( day - 272- InLeapYear(t)); |
| 417 |
} |
| 418 |
if ( month == 10 ) { |
| 419 |
return ( day - 303- InLeapYear(t)); |
| 420 |
} |
| 421 |
if ( month == 11 ) { |
| 422 |
return ( day - 333- InLeapYear(t)); |
| 423 |
} |
| 424 |
|
| 425 |
return ("ERROR: DateFromTime("+t+") not known" ); |
| 426 |
} |
| 427 |
function WeekDay( t ) { |
| 428 |
var weekday = (Day(t)+4) % 7; |
| 429 |
return( weekday < 0 ? 7 + weekday : weekday ); |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
function HourFromTime( t ) { |
| 435 |
var h = Math.floor( t / msPerHour ) % HoursPerDay; |
| 436 |
return ( (h<0) ? HoursPerDay + h : h ); |
| 437 |
} |
| 438 |
function MinFromTime( t ) { |
| 439 |
var min = Math.floor( t / msPerMinute ) % MinutesPerHour; |
| 440 |
return( ( min < 0 ) ? MinutesPerHour + min : min ); |
| 441 |
} |
| 442 |
function SecFromTime( t ) { |
| 443 |
var sec = Math.floor( t / msPerSecond ) % SecondsPerMinute; |
| 444 |
return ( (sec < 0 ) ? SecondsPerMinute + sec : sec ); |
| 445 |
} |
| 446 |
function msFromTime( t ) { |
| 447 |
var ms = t % msPerSecond; |
| 448 |
return ( (ms < 0 ) ? msPerSecond + ms : ms ); |
| 449 |
} |
| 450 |
function LocalTZA() { |
| 451 |
return ( TZ_DIFF * msPerHour ); |
| 452 |
} |
| 453 |
function UTC( t ) { |
| 454 |
return ( t - LocalTZA() - DaylightSavingTA(t - LocalTZA()) ); |
| 455 |
} |
| 456 |
function DaylightSavingTA( t ) { |
| 457 |
t = t - LocalTZA(); |
| 458 |
|
| 459 |
var dst_start = GetFirstSundayInApril(t) + 2*msPerHour; |
| 460 |
var dst_end = GetLastSundayInOctober(t)+ 2*msPerHour; |
| 461 |
|
| 462 |
if ( t >= dst_start && t < dst_end ) { |
| 463 |
return msPerHour; |
| 464 |
} else { |
| 465 |
return 0; |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
print( new Date( UTC(dst_start + LocalTZA())) ); |
| 472 |
|
| 473 |
return UTC(dst_start + LocalTZA()); |
| 474 |
} |
| 475 |
function GetFirstSundayInApril( t ) { |
| 476 |
var year = YearFromTime(t); |
| 477 |
var leap = InLeapYear(t); |
| 478 |
|
| 479 |
var april = TimeFromYear(year) + TimeInMonth(0, leap) + TimeInMonth(1,leap) + |
| 480 |
TimeInMonth(2,leap); |
| 481 |
|
| 482 |
for ( var first_sunday = april; WeekDay(first_sunday) > 0; |
| 483 |
first_sunday += msPerDay ) |
| 484 |
{ |
| 485 |
; |
| 486 |
} |
| 487 |
|
| 488 |
return first_sunday; |
| 489 |
} |
| 490 |
function GetLastSundayInOctober( t ) { |
| 491 |
var year = YearFromTime(t); |
| 492 |
var leap = InLeapYear(t); |
| 493 |
|
| 494 |
for ( var oct = TimeFromYear(year), m = 0; m < 9; m++ ) { |
| 495 |
oct += TimeInMonth(m, leap); |
| 496 |
} |
| 497 |
for ( var last_sunday = oct + 30*msPerDay; WeekDay(last_sunday) > 0; |
| 498 |
last_sunday -= msPerDay ) |
| 499 |
{ |
| 500 |
; |
| 501 |
} |
| 502 |
return last_sunday; |
| 503 |
} |
| 504 |
function LocalTime( t ) { |
| 505 |
return ( t + LocalTZA() + DaylightSavingTA(t) ); |
| 506 |
} |
| 507 |
function MakeTime( hour, min, sec, ms ) { |
| 508 |
if ( isNaN( hour ) || isNaN( min ) || isNaN( sec ) || isNaN( ms ) ) { |
| 509 |
return Number.NaN; |
| 510 |
} |
| 511 |
|
| 512 |
hour = ToInteger(hour); |
| 513 |
min = ToInteger( min); |
| 514 |
sec = ToInteger( sec); |
| 515 |
ms = ToInteger( ms ); |
| 516 |
|
| 517 |
return( (hour*msPerHour) + (min*msPerMinute) + |
| 518 |
(sec*msPerSecond) + ms ); |
| 519 |
} |
| 520 |
function MakeDay( year, month, date ) { |
| 521 |
if ( isNaN(year) || isNaN(month) || isNaN(date) ) { |
| 522 |
return Number.NaN; |
| 523 |
} |
| 524 |
year = ToInteger(year); |
| 525 |
month = ToInteger(month); |
| 526 |
date = ToInteger(date ); |
| 527 |
|
| 528 |
var sign = ( year < 1970 ) ? -1 : 1; |
| 529 |
var t = ( year < 1970 ) ? 1 : 0; |
| 530 |
var y = ( year < 1970 ) ? 1969 : 1970; |
| 531 |
|
| 532 |
var result5 = year + Math.floor( month/12 ); |
| 533 |
var result6 = month % 12; |
| 534 |
|
| 535 |
if ( year < 1970 ) { |
| 536 |
for ( y = 1969; y >= year; y += sign ) { |
| 537 |
t += sign * TimeInYear(y); |
| 538 |
} |
| 539 |
} else { |
| 540 |
for ( y = 1970 ; y < year; y += sign ) { |
| 541 |
t += sign * TimeInYear(y); |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
var leap = InLeapYear( t ); |
| 546 |
|
| 547 |
for ( var m = 0; m < month; m++ ) { |
| 548 |
t += TimeInMonth( m, leap ); |
| 549 |
} |
| 550 |
|
| 551 |
if ( YearFromTime(t) != result5 ) { |
| 552 |
return Number.NaN; |
| 553 |
} |
| 554 |
if ( MonthFromTime(t) != result6 ) { |
| 555 |
return Number.NaN; |
| 556 |
} |
| 557 |
if ( DateFromTime(t) != 1 ) { |
| 558 |
return Number.NaN; |
| 559 |
} |
| 560 |
|
| 561 |
return ( (Day(t)) + date - 1 ); |
| 562 |
} |
| 563 |
function TimeInMonth( month, leap ) { |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
if ( month == 3 || month == 5 || month == 8 || month == 10 ) { |
| 569 |
return ( 30*msPerDay ); |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
if ( month == 0 || month == 2 || month == 4 || month == 6 || |
| 574 |
month == 7 || month == 9 || month == 11 ) { |
| 575 |
return ( 31*msPerDay ); |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
return ( (leap == 0) ? 28*msPerDay : 29*msPerDay ); |
| 580 |
} |
| 581 |
function MakeDate( day, time ) { |
| 582 |
if ( day == Number.POSITIVE_INFINITY || |
| 583 |
day == Number.NEGATIVE_INFINITY || |
| 584 |
day == Number.NaN ) { |
| 585 |
return Number.NaN; |
| 586 |
} |
| 587 |
if ( time == Number.POSITIVE_INFINITY || |
| 588 |
time == Number.POSITIVE_INFINITY || |
| 589 |
day == Number.NaN) { |
| 590 |
return Number.NaN; |
| 591 |
} |
| 592 |
return ( day * msPerDay ) + time; |
| 593 |
} |
| 594 |
function TimeClip( t ) { |
| 595 |
if ( isNaN( t ) ) { |
| 596 |
return ( Number.NaN ); |
| 597 |
} |
| 598 |
if ( Math.abs( t ) > 8.64e15 ) { |
| 599 |
return ( Number.NaN ); |
| 600 |
} |
| 601 |
|
| 602 |
return ( ToInteger( t ) ); |
| 603 |
} |
| 604 |
function ToInteger( t ) { |
| 605 |
t = Number( t ); |
| 606 |
|
| 607 |
if ( isNaN( t ) ){ |
| 608 |
return ( Number.NaN ); |
| 609 |
} |
| 610 |
if ( t == 0 || t == -0 || |
| 611 |
t == Number.POSITIVE_INFINITY || t == Number.NEGATIVE_INFINITY ) { |
| 612 |
return 0; |
| 613 |
} |
| 614 |
|
| 615 |
var sign = ( t < 0 ) ? -1 : 1; |
| 616 |
|
| 617 |
return ( sign * Math.floor( Math.abs( t ) ) ); |
| 618 |
} |
| 619 |
function Enumerate ( o ) { |
| 620 |
var properties = new Array(); |
| 621 |
for ( p in o ) { |
| 622 |
properties[ properties.length ] = new Array( p, o[p] ); |
| 623 |
} |
| 624 |
return properties; |
| 625 |
} |
| 626 |
function AddTestCase( description, expect, actual ) { |
| 627 |
testcases[tc++] = new TestCase( SECTION, description, expect, actual ); |
| 628 |
} |
| 629 |
|
| 630 |
function getFailedCases() { |
| 631 |
for ( var i = 0; i < testcases.length; i++ ) { |
| 632 |
if ( ! testcases[i].passed ) { |
| 633 |
print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect ); |
| 634 |
} |
| 635 |
} |
| 636 |
} |