| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 + TO_INTEGER(ms); | 253 + TO_INTEGER(ms); |
| 254 } | 254 } |
| 255 | 255 |
| 256 | 256 |
| 257 // ECMA 262 - 15.9.1.12 | 257 // ECMA 262 - 15.9.1.12 |
| 258 function TimeInYear(year) { | 258 function TimeInYear(year) { |
| 259 return DaysInYear(year) * msPerDay; | 259 return DaysInYear(year) * msPerDay; |
| 260 } | 260 } |
| 261 | 261 |
| 262 | 262 |
| 263 var four_year_cycle_table = CalculateDateTable(); | 263 var ymd_from_time_cache = [$NaN, $NaN, $NaN]; |
| 264 var ymd_from_time_cached_time = $NaN; |
| 264 | 265 |
| 266 function YearFromTime(t) { |
| 267 if (t !== ymd_from_time_cached_time) { |
| 268 // Limits according to ECMA 262 15.9.1.1 |
| 269 if (!$isFinite(t) || t < -8640000000000000 || t > 8640000000000000) { |
| 270 return $NaN; |
| 271 } |
| 265 | 272 |
| 266 function CalculateDateTable() { | 273 %DateYMDFromTime(t, ymd_from_time_cache); |
| 267 var month_lengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; | 274 ymd_from_time_cached_time = t |
| 268 var four_year_cycle_table = new $Array(1461); | 275 } |
| 269 | 276 |
| 270 var cumulative = 0; | 277 return ymd_from_time_cache[0]; |
| 271 var position = 0; | 278 } |
| 272 var leap_position = 0; | 279 |
| 273 for (var month = 0; month < 12; month++) { | 280 function MonthFromTime(t) { |
| 274 var month_bits = month << kMonthShift; | 281 if (t !== ymd_from_time_cached_time) { |
| 275 var length = month_lengths[month]; | 282 // Limits according to ECMA 262 15.9.1.1 |
| 276 for (var day = 1; day <= length; day++) { | 283 if (!$isFinite(t) || t < -8640000000000000 || t > 8640000000000000) { |
| 277 four_year_cycle_table[leap_position] = | 284 return $NaN; |
| 278 month_bits + day; | |
| 279 four_year_cycle_table[366 + position] = | |
| 280 (1 << kYearShift) + month_bits + day; | |
| 281 four_year_cycle_table[731 + position] = | |
| 282 (2 << kYearShift) + month_bits + day; | |
| 283 four_year_cycle_table[1096 + position] = | |
| 284 (3 << kYearShift) + month_bits + day; | |
| 285 leap_position++; | |
| 286 position++; | |
| 287 } | 285 } |
| 288 if (month == 1) { | 286 %DateYMDFromTime(t, ymd_from_time_cache); |
| 289 four_year_cycle_table[leap_position++] = month_bits + 29; | 287 ymd_from_time_cached_time = t |
| 288 } |
| 289 |
| 290 return ymd_from_time_cache[1]; |
| 291 } |
| 292 |
| 293 function DateFromTime(t) { |
| 294 if (t !== ymd_from_time_cached_time) { |
| 295 // Limits according to ECMA 262 15.9.1.1 |
| 296 if (!$isFinite(t) || t < -8640000000000000 || t > 8640000000000000) { |
| 297 return $NaN; |
| 290 } | 298 } |
| 299 |
| 300 %DateYMDFromTime(t, ymd_from_time_cache); |
| 301 ymd_from_time_cached_time = t |
| 291 } | 302 } |
| 292 return four_year_cycle_table; | 303 |
| 304 return ymd_from_time_cache[2]; |
| 293 } | 305 } |
| 294 | 306 |
| 295 | 307 |
| 296 // Constructor for creating objects holding year, month, and date. | |
| 297 // Introduced to ensure the two return points in FromJulianDay match same map. | |
| 298 function DayTriplet(year, month, date) { | |
| 299 this.year = year; | |
| 300 this.month = month; | |
| 301 this.date = date; | |
| 302 } | |
| 303 | |
| 304 var julian_day_cache_triplet; | |
| 305 var julian_day_cache_day = $NaN; | |
| 306 | |
| 307 // Compute year, month, and day from modified Julian day. | |
| 308 // The missing days in 1582 are ignored for JavaScript compatibility. | |
| 309 function FromJulianDay(julian) { | |
| 310 if (julian_day_cache_day == julian) { | |
| 311 return julian_day_cache_triplet; | |
| 312 } | |
| 313 var result; | |
| 314 // Avoid floating point and non-Smi maths in common case. This is also a peri
od of | |
| 315 // time where leap years are very regular. The range is not too large to avoi
d overflow | |
| 316 // when doing the multiply-to-divide trick. | |
| 317 if (julian > kDayZeroInJulianDay && | |
| 318 (julian - kDayZeroInJulianDay) < 40177) { // 1970 - 2080 | |
| 319 var jsimple = (julian - kDayZeroInJulianDay) + 731; // Day 0 is 1st January
1968 | |
| 320 var y = 1968; | |
| 321 // Divide by 1461 by multiplying with 22967 and shifting down by 25! | |
| 322 var after_1968 = (jsimple * 22967) >> 25; | |
| 323 y += after_1968 << 2; | |
| 324 jsimple -= 1461 * after_1968; | |
| 325 var four_year_cycle = four_year_cycle_table[jsimple]; | |
| 326 result = new DayTriplet(y + (four_year_cycle >> kYearShift), | |
| 327 (four_year_cycle & kMonthMask) >> kMonthShift, | |
| 328 four_year_cycle & kDayMask); | |
| 329 } else { | |
| 330 var jalpha = FLOOR((julian - 1867216.25) / 36524.25); | |
| 331 var jb = julian + 1 + jalpha - FLOOR(0.25 * jalpha) + 1524; | |
| 332 var jc = FLOOR(6680.0 + ((jb-2439870) - 122.1)/365.25); | |
| 333 var jd = FLOOR(365 * jc + (0.25 * jc)); | |
| 334 var je = FLOOR((jb - jd)/30.6001); | |
| 335 var m = je - 1; | |
| 336 if (m > 12) m -= 13; | |
| 337 var y = jc - 4715; | |
| 338 if (m > 2) { --y; --m; } | |
| 339 var d = jb - jd - FLOOR(30.6001 * je); | |
| 340 result = new DayTriplet(y, m, d); | |
| 341 } | |
| 342 julian_day_cache_day = julian; | |
| 343 julian_day_cache_triplet = result; | |
| 344 return result; | |
| 345 } | |
| 346 | |
| 347 | |
| 348 // Compute number of days given a year, month, date. | 308 // Compute number of days given a year, month, date. |
| 349 // Note that month and date can lie outside the normal range. | 309 // Note that month and date can lie outside the normal range. |
| 350 // For example: | 310 // For example: |
| 351 // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20) | 311 // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20) |
| 352 // MakeDay(2007, -33, 1) --> MakeDay(2004, 3, 1) | 312 // MakeDay(2007, -33, 1) --> MakeDay(2004, 3, 1) |
| 353 // MakeDay(2007, 14, -50) --> MakeDay(2007, 8, 11) | 313 // MakeDay(2007, 14, -50) --> MakeDay(2007, 8, 11) |
| 354 function MakeDay(year, month, date) { | 314 function MakeDay(year, month, date) { |
| 355 if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) return $NaN; | 315 if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) return $NaN; |
| 356 | 316 |
| 357 year = TO_INTEGER(year); | 317 year = TO_INTEGER(year); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; | 530 var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; |
| 571 var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oc
t', 'Nov', 'Dec']; | 531 var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oc
t', 'Nov', 'Dec']; |
| 572 | 532 |
| 573 | 533 |
| 574 function TwoDigitString(value) { | 534 function TwoDigitString(value) { |
| 575 return value < 10 ? "0" + value : "" + value; | 535 return value < 10 ? "0" + value : "" + value; |
| 576 } | 536 } |
| 577 | 537 |
| 578 | 538 |
| 579 function DateString(time) { | 539 function DateString(time) { |
| 580 var YMD = FromJulianDay(DAY(time) + kDayZeroInJulianDay); | |
| 581 return WeekDays[WeekDay(time)] + ' ' | 540 return WeekDays[WeekDay(time)] + ' ' |
| 582 + Months[YMD.month] + ' ' | 541 + Months[MonthFromTime(time)] + ' ' |
| 583 + TwoDigitString(YMD.date) + ' ' | 542 + TwoDigitString(DateFromTime(time)) + ' ' |
| 584 + YMD.year; | 543 + YearFromTime(time); |
| 585 } | 544 } |
| 586 | 545 |
| 587 | 546 |
| 588 var LongWeekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Fri
day', 'Saturday']; | 547 var LongWeekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Fri
day', 'Saturday']; |
| 589 var LongMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July'
, 'August', 'September', 'October', 'November', 'December']; | 548 var LongMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July'
, 'August', 'September', 'October', 'November', 'December']; |
| 590 | 549 |
| 591 | 550 |
| 592 function LongDateString(time) { | 551 function LongDateString(time) { |
| 593 var YMD = FromJulianDay(DAY(time) + kDayZeroInJulianDay); | |
| 594 return LongWeekDays[WeekDay(time)] + ', ' | 552 return LongWeekDays[WeekDay(time)] + ', ' |
| 595 + LongMonths[YMD.month] + ' ' | 553 + LongMonths[MonthFromTime(time)] + ' ' |
| 596 + TwoDigitString(YMD.date) + ', ' | 554 + TwoDigitString(DateFromTime(time)) + ', ' |
| 597 + YMD.year; | 555 + YearFromTime(time); |
| 598 } | 556 } |
| 599 | 557 |
| 600 | 558 |
| 601 function TimeString(time) { | 559 function TimeString(time) { |
| 602 return TwoDigitString(HOUR_FROM_TIME(time)) + ':' | 560 return TwoDigitString(HOUR_FROM_TIME(time)) + ':' |
| 603 + TwoDigitString(MIN_FROM_TIME(time)) + ':' | 561 + TwoDigitString(MIN_FROM_TIME(time)) + ':' |
| 604 + TwoDigitString(SEC_FROM_TIME(time)); | 562 + TwoDigitString(SEC_FROM_TIME(time)); |
| 605 } | 563 } |
| 606 | 564 |
| 607 | 565 |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 "toGMTString", DateToGMTString, | 1080 "toGMTString", DateToGMTString, |
| 1123 "toUTCString", DateToUTCString, | 1081 "toUTCString", DateToUTCString, |
| 1124 "getYear", DateGetYear, | 1082 "getYear", DateGetYear, |
| 1125 "setYear", DateSetYear, | 1083 "setYear", DateSetYear, |
| 1126 "toISOString", DateToISOString, | 1084 "toISOString", DateToISOString, |
| 1127 "toJSON", DateToJSON | 1085 "toJSON", DateToJSON |
| 1128 )); | 1086 )); |
| 1129 } | 1087 } |
| 1130 | 1088 |
| 1131 SetupDate(); | 1089 SetupDate(); |
| OLD | NEW |