| 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 25 matching lines...) Expand all Loading... |
| 36 // This file contains date support implemented in JavaScript. | 36 // This file contains date support implemented in JavaScript. |
| 37 | 37 |
| 38 | 38 |
| 39 // Keep reference to original values of some global properties. This | 39 // Keep reference to original values of some global properties. This |
| 40 // has the added benefit that the code in this file is isolated from | 40 // has the added benefit that the code in this file is isolated from |
| 41 // changes to these properties. | 41 // changes to these properties. |
| 42 const $Date = global.Date; | 42 const $Date = global.Date; |
| 43 | 43 |
| 44 // ECMA 262 - 15.9.1.2 | 44 // ECMA 262 - 15.9.1.2 |
| 45 function Day(time) { | 45 function Day(time) { |
| 46 return $floor(time/msPerDay); | 46 return FLOOR(time/msPerDay); |
| 47 } | 47 } |
| 48 | 48 |
| 49 | 49 |
| 50 // ECMA 262 - 5.2 | 50 // ECMA 262 - 5.2 |
| 51 function Modulo(value, remainder) { | 51 function Modulo(value, remainder) { |
| 52 var mod = value % remainder; | 52 var mod = value % remainder; |
| 53 return mod >= 0 ? mod : mod + remainder; | 53 return mod >= 0 ? mod : mod + remainder; |
| 54 } | 54 } |
| 55 | 55 |
| 56 | 56 |
| 57 function TimeWithinDay(time) { | 57 function TimeWithinDay(time) { |
| 58 return Modulo(time, msPerDay); | 58 return Modulo(time, msPerDay); |
| 59 } | 59 } |
| 60 | 60 |
| 61 | 61 |
| 62 // ECMA 262 - 15.9.1.3 | 62 // ECMA 262 - 15.9.1.3 |
| 63 function DaysInYear(year) { | 63 function DaysInYear(year) { |
| 64 if (year % 4 != 0) return 365; | 64 if (year % 4 != 0) return 365; |
| 65 if ((year % 100 == 0) && (year % 400 != 0)) return 365; | 65 if ((year % 100 == 0) && (year % 400 != 0)) return 365; |
| 66 return 366; | 66 return 366; |
| 67 } | 67 } |
| 68 | 68 |
| 69 | 69 |
| 70 function DayFromYear(year) { | 70 function DayFromYear(year) { |
| 71 return 365 * (year-1970) | 71 return 365 * (year-1970) |
| 72 + $floor((year-1969)/4) | 72 + FLOOR((year-1969)/4) |
| 73 - $floor((year-1901)/100) | 73 - FLOOR((year-1901)/100) |
| 74 + $floor((year-1601)/400); | 74 + FLOOR((year-1601)/400); |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 function TimeFromYear(year) { | 78 function TimeFromYear(year) { |
| 79 return msPerDay * DayFromYear(year); | 79 return msPerDay * DayFromYear(year); |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 function YearFromTime(time) { | 83 function YearFromTime(time) { |
| 84 return FromJulianDay(Day(time) + kDayZeroInJulianDay).year; | 84 return FromJulianDay(Day(time) + kDayZeroInJulianDay).year; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 return Modulo(Day(time) + 4, 7); | 163 return Modulo(Day(time) + 4, 7); |
| 164 } | 164 } |
| 165 | 165 |
| 166 var local_time_offset = %DateLocalTimeOffset(); | 166 var local_time_offset = %DateLocalTimeOffset(); |
| 167 | 167 |
| 168 function LocalTime(time) { | 168 function LocalTime(time) { |
| 169 if ($isNaN(time)) return time; | 169 if ($isNaN(time)) return time; |
| 170 return time + local_time_offset + DaylightSavingsOffset(time); | 170 return time + local_time_offset + DaylightSavingsOffset(time); |
| 171 } | 171 } |
| 172 | 172 |
| 173 function LocalTimeNoCheck(time) { |
| 174 return time + local_time_offset + DaylightSavingsOffset(time); |
| 175 } |
| 176 |
| 173 | 177 |
| 174 function UTC(time) { | 178 function UTC(time) { |
| 175 if ($isNaN(time)) return time; | 179 if ($isNaN(time)) return time; |
| 176 var tmp = time - local_time_offset; | 180 var tmp = time - local_time_offset; |
| 177 return tmp - DaylightSavingsOffset(tmp); | 181 return tmp - DaylightSavingsOffset(tmp); |
| 178 } | 182 } |
| 179 | 183 |
| 180 | 184 |
| 181 // ECMA 262 - 15.9.1.10 | 185 // ECMA 262 - 15.9.1.10 |
| 182 function HourFromTime(time) { | 186 function HourFromTime(time) { |
| 183 return Modulo($floor(time / msPerHour), HoursPerDay); | 187 return Modulo(FLOOR(time / msPerHour), HoursPerDay); |
| 184 } | 188 } |
| 185 | 189 |
| 186 | 190 |
| 187 function MinFromTime(time) { | 191 function MinFromTime(time) { |
| 188 return Modulo($floor(time / msPerMinute), MinutesPerHour); | 192 return Modulo(FLOOR(time / msPerMinute), MinutesPerHour); |
| 189 } | 193 } |
| 190 | 194 |
| 191 | 195 |
| 192 function SecFromTime(time) { | 196 function SecFromTime(time) { |
| 193 return Modulo($floor(time / msPerSecond), SecondsPerMinute); | 197 return Modulo(FLOOR(time / msPerSecond), SecondsPerMinute); |
| 194 } | 198 } |
| 195 | 199 |
| 196 | 200 |
| 197 function msFromTime(time) { | 201 function msFromTime(time) { |
| 198 return Modulo(time, msPerSecond); | 202 return Modulo(time, msPerSecond); |
| 199 } | 203 } |
| 200 | 204 |
| 201 | 205 |
| 202 // ECMA 262 - 15.9.1.11 | 206 // ECMA 262 - 15.9.1.11 |
| 203 function MakeTime(hour, min, sec, ms) { | 207 function MakeTime(hour, min, sec, ms) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 216 function TimeInYear(year) { | 220 function TimeInYear(year) { |
| 217 return DaysInYear(year) * msPerDay; | 221 return DaysInYear(year) * msPerDay; |
| 218 } | 222 } |
| 219 | 223 |
| 220 | 224 |
| 221 // Compute modified Julian day from year, month, date. | 225 // Compute modified Julian day from year, month, date. |
| 222 // The missing days in 1582 are ignored for JavaScript compatibility. | 226 // The missing days in 1582 are ignored for JavaScript compatibility. |
| 223 function ToJulianDay(year, month, date) { | 227 function ToJulianDay(year, month, date) { |
| 224 var jy = (month > 1) ? year : year - 1; | 228 var jy = (month > 1) ? year : year - 1; |
| 225 var jm = (month > 1) ? month + 2 : month + 14; | 229 var jm = (month > 1) ? month + 2 : month + 14; |
| 226 var ja = $floor(0.01*jy); | 230 var ja = FLOOR(0.01*jy); |
| 227 return $floor($floor(365.25*jy) + $floor(30.6001*jm) + date + 1720995) + 2 - j
a + $floor(0.25*ja); | 231 return FLOOR(FLOOR(365.25*jy) + FLOOR(30.6001*jm) + date + 1720995) + 2 - ja +
FLOOR(0.25*ja); |
| 228 } | 232 } |
| 229 | 233 |
| 230 | 234 var four_year_cycle_table = CalculateDateTable(); |
| 231 var four_year_cycle_table; | |
| 232 | 235 |
| 233 | 236 |
| 234 function CalculateDateTable() { | 237 function CalculateDateTable() { |
| 235 var month_lengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; | 238 var month_lengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; |
| 236 var four_year_cycle_table = new $Array(1461); | 239 var four_year_cycle_table = new $Array(1461); |
| 237 | 240 |
| 238 var cumulative = 0; | 241 var cumulative = 0; |
| 239 var position = 0; | 242 var position = 0; |
| 240 var leap_position = 0; | 243 var leap_position = 0; |
| 241 for (var month = 0; month < 12; month++) { | 244 for (var month = 0; month < 12; month++) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 254 } | 257 } |
| 255 if (month == 1) { | 258 if (month == 1) { |
| 256 four_year_cycle_table[leap_position++] = | 259 four_year_cycle_table[leap_position++] = |
| 257 (month << kMonthShift) + 29; | 260 (month << kMonthShift) + 29; |
| 258 } | 261 } |
| 259 } | 262 } |
| 260 return four_year_cycle_table; | 263 return four_year_cycle_table; |
| 261 } | 264 } |
| 262 | 265 |
| 263 | 266 |
| 264 | |
| 265 // Constructor for creating objects holding year, month, and date. | 267 // Constructor for creating objects holding year, month, and date. |
| 266 // Introduced to ensure the two return points in FromJulianDay match same map. | 268 // Introduced to ensure the two return points in FromJulianDay match same map. |
| 267 function DayTriplet(year, month, date) { | 269 function DayTriplet(year, month, date) { |
| 268 this.year = year; | 270 this.year = year; |
| 269 this.month = month; | 271 this.month = month; |
| 270 this.date = date; | 272 this.date = date; |
| 271 } | 273 } |
| 272 | 274 |
| 273 | 275 |
| 274 // Compute year, month, and day from modified Julian day. | 276 // Compute year, month, and day from modified Julian day. |
| 275 // The missing days in 1582 are ignored for JavaScript compatibility. | 277 // The missing days in 1582 are ignored for JavaScript compatibility. |
| 276 function FromJulianDay(julian) { | 278 function FromJulianDay(julian) { |
| 277 // Avoid floating point and non-Smi maths in common case. This is also a peri
od of | 279 // Avoid floating point and non-Smi maths in common case. This is also a peri
od of |
| 278 // time where leap years are very regular. The range is not too large to avoi
d overflow | 280 // time where leap years are very regular. The range is not too large to avoi
d overflow |
| 279 // when doing the multiply-to-divide trick. | 281 // when doing the multiply-to-divide trick. |
| 280 if (julian > kDayZeroInJulianDay && | 282 if (julian > kDayZeroInJulianDay && |
| 281 (julian - kDayZeroInJulianDay) < 40177) { // 1970 - 2080 | 283 (julian - kDayZeroInJulianDay) < 40177) { // 1970 - 2080 |
| 282 if (!four_year_cycle_table) | |
| 283 four_year_cycle_table = CalculateDateTable(); | |
| 284 var jsimple = (julian - kDayZeroInJulianDay) + 731; // Day 0 is 1st January
1968 | 284 var jsimple = (julian - kDayZeroInJulianDay) + 731; // Day 0 is 1st January
1968 |
| 285 var y = 1968; | 285 var y = 1968; |
| 286 // Divide by 1461 by multiplying with 22967 and shifting down by 25! | 286 // Divide by 1461 by multiplying with 22967 and shifting down by 25! |
| 287 var after_1968 = (jsimple * 22967) >> 25; | 287 var after_1968 = (jsimple * 22967) >> 25; |
| 288 y += after_1968 << 2; | 288 y += after_1968 << 2; |
| 289 jsimple -= 1461 * after_1968; | 289 jsimple -= 1461 * after_1968; |
| 290 var four_year_cycle = four_year_cycle_table[jsimple]; | 290 var four_year_cycle = four_year_cycle_table[jsimple]; |
| 291 return new DayTriplet(y + (four_year_cycle >> kYearShift), | 291 return new DayTriplet(y + (four_year_cycle >> kYearShift), |
| 292 (four_year_cycle & kMonthMask) >> kMonthShift, | 292 (four_year_cycle & kMonthMask) >> kMonthShift, |
| 293 four_year_cycle & kDayMask); | 293 four_year_cycle & kDayMask); |
| 294 } | 294 } |
| 295 var jalpha = $floor((julian - 1867216.25) / 36524.25); | 295 var jalpha = FLOOR((julian - 1867216.25) / 36524.25); |
| 296 var jb = julian + 1 + jalpha - $floor(0.25 * jalpha) + 1524; | 296 var jb = julian + 1 + jalpha - FLOOR(0.25 * jalpha) + 1524; |
| 297 var jc = $floor(6680.0 + ((jb-2439870) - 122.1)/365.25); | 297 var jc = FLOOR(6680.0 + ((jb-2439870) - 122.1)/365.25); |
| 298 var jd = $floor(365 * jc + (0.25 * jc)); | 298 var jd = FLOOR(365 * jc + (0.25 * jc)); |
| 299 var je = $floor((jb - jd)/30.6001); | 299 var je = FLOOR((jb - jd)/30.6001); |
| 300 var m = je - 1; | 300 var m = je - 1; |
| 301 if (m > 12) m -= 13; | 301 if (m > 12) m -= 13; |
| 302 var y = jc - 4715; | 302 var y = jc - 4715; |
| 303 if (m > 2) { --y; --m; } | 303 if (m > 2) { --y; --m; } |
| 304 var d = jb - jd - $floor(30.6001 * je); | 304 var d = jb - jd - FLOOR(30.6001 * je); |
| 305 return new DayTriplet(y, m, d); | 305 return new DayTriplet(y, m, d); |
| 306 } | 306 } |
| 307 | 307 |
| 308 |
| 308 // Compute number of days given a year, month, date. | 309 // Compute number of days given a year, month, date. |
| 309 // Note that month and date can lie outside the normal range. | 310 // Note that month and date can lie outside the normal range. |
| 310 // For example: | 311 // For example: |
| 311 // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20) | 312 // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20) |
| 312 // MakeDay(2007, -33, 1) --> MakeDay(2004, 3, 1) | 313 // MakeDay(2007, -33, 1) --> MakeDay(2004, 3, 1) |
| 313 // MakeDay(2007, 14, -50) --> MakeDay(2007, 8, 11) | 314 // MakeDay(2007, 14, -50) --> MakeDay(2007, 8, 11) |
| 314 function MakeDay(year, month, date) { | 315 function MakeDay(year, month, date) { |
| 315 if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) return $NaN; | 316 if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) return $NaN; |
| 316 | 317 |
| 317 // Conversion to integers. | 318 // Conversion to integers. |
| 318 year = TO_INTEGER(year); | 319 year = TO_INTEGER(year); |
| 319 month = TO_INTEGER(month); | 320 month = TO_INTEGER(month); |
| 320 date = TO_INTEGER(date); | 321 date = TO_INTEGER(date); |
| 321 | 322 |
| 322 // Overflow months into year. | 323 // Overflow months into year. |
| 323 year = year + $floor(month/12); | 324 year = year + FLOOR(month/12); |
| 324 month = month % 12; | 325 month = month % 12; |
| 325 if (month < 0) { | 326 if (month < 0) { |
| 326 month += 12; | 327 month += 12; |
| 327 } | 328 } |
| 328 | 329 |
| 329 // Return days relative to Jan 1 1970. | 330 // Return days relative to Jan 1 1970. |
| 330 return ToJulianDay(year, month, date) - kDayZeroInJulianDay; | 331 return ToJulianDay(year, month, date) - kDayZeroInJulianDay; |
| 331 } | 332 } |
| 332 | 333 |
| 333 | 334 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 // Helper functions. | 394 // Helper functions. |
| 394 function GetTimeFrom(aDate) { | 395 function GetTimeFrom(aDate) { |
| 395 if (IS_DATE(aDate)) return %_ValueOf(aDate); | 396 if (IS_DATE(aDate)) return %_ValueOf(aDate); |
| 396 throw new $TypeError('this is not a Date object.'); | 397 throw new $TypeError('this is not a Date object.'); |
| 397 } | 398 } |
| 398 | 399 |
| 399 | 400 |
| 400 function GetMillisecondsFrom(aDate) { | 401 function GetMillisecondsFrom(aDate) { |
| 401 var t = GetTimeFrom(aDate); | 402 var t = GetTimeFrom(aDate); |
| 402 if ($isNaN(t)) return t; | 403 if ($isNaN(t)) return t; |
| 403 return msFromTime(LocalTime(t)); | 404 return msFromTime(LocalTimeNoCheck(t)); |
| 404 } | 405 } |
| 405 | 406 |
| 406 | 407 |
| 407 function GetUTCMillisecondsFrom(aDate) { | 408 function GetUTCMillisecondsFrom(aDate) { |
| 408 var t = GetTimeFrom(aDate); | 409 var t = GetTimeFrom(aDate); |
| 409 if ($isNaN(t)) return t; | 410 if ($isNaN(t)) return t; |
| 410 return msFromTime(t); | 411 return msFromTime(t); |
| 411 } | 412 } |
| 412 | 413 |
| 413 | 414 |
| 414 function GetSecondsFrom(aDate) { | 415 function GetSecondsFrom(aDate) { |
| 415 var t = GetTimeFrom(aDate); | 416 var t = GetTimeFrom(aDate); |
| 416 if ($isNaN(t)) return t; | 417 if ($isNaN(t)) return t; |
| 417 return SecFromTime(LocalTime(t)); | 418 return SecFromTime(LocalTimeNoCheck(t)); |
| 418 } | 419 } |
| 419 | 420 |
| 420 | 421 |
| 421 function GetUTCSecondsFrom(aDate) { | 422 function GetUTCSecondsFrom(aDate) { |
| 422 var t = GetTimeFrom(aDate); | 423 var t = GetTimeFrom(aDate); |
| 423 if ($isNaN(t)) return t; | 424 if ($isNaN(t)) return t; |
| 424 return SecFromTime(t); | 425 return SecFromTime(t); |
| 425 } | 426 } |
| 426 | 427 |
| 427 | 428 |
| 428 function GetMinutesFrom(aDate) { | 429 function GetMinutesFrom(aDate) { |
| 429 var t = GetTimeFrom(aDate); | 430 var t = GetTimeFrom(aDate); |
| 430 if ($isNaN(t)) return t; | 431 if ($isNaN(t)) return t; |
| 431 return MinFromTime(LocalTime(t)); | 432 return MinFromTime(LocalTimeNoCheck(t)); |
| 432 } | 433 } |
| 433 | 434 |
| 434 | 435 |
| 435 function GetUTCMinutesFrom(aDate) { | 436 function GetUTCMinutesFrom(aDate) { |
| 436 var t = GetTimeFrom(aDate); | 437 var t = GetTimeFrom(aDate); |
| 437 if ($isNaN(t)) return t; | 438 if ($isNaN(t)) return t; |
| 438 return MinFromTime(t); | 439 return MinFromTime(t); |
| 439 } | 440 } |
| 440 | 441 |
| 441 | 442 |
| 442 function GetHoursFrom(aDate) { | 443 function GetHoursFrom(aDate) { |
| 443 var t = GetTimeFrom(aDate); | 444 var t = GetTimeFrom(aDate); |
| 444 if ($isNaN(t)) return t; | 445 if ($isNaN(t)) return t; |
| 445 return HourFromTime(LocalTime(t)); | 446 return HourFromTime(LocalTimeNoCheck(t)); |
| 446 } | 447 } |
| 447 | 448 |
| 448 | 449 |
| 449 function GetUTCHoursFrom(aDate) { | 450 function GetUTCHoursFrom(aDate) { |
| 450 var t = GetTimeFrom(aDate); | 451 var t = GetTimeFrom(aDate); |
| 451 if ($isNaN(t)) return t; | 452 if ($isNaN(t)) return t; |
| 452 return HourFromTime(t); | 453 return HourFromTime(t); |
| 453 } | 454 } |
| 454 | 455 |
| 455 | 456 |
| 456 function GetFullYearFrom(aDate) { | 457 function GetFullYearFrom(aDate) { |
| 457 var t = GetTimeFrom(aDate); | 458 var t = GetTimeFrom(aDate); |
| 458 if ($isNaN(t)) return t; | 459 if ($isNaN(t)) return t; |
| 459 return YearFromTime(LocalTime(t)); | 460 return YearFromTime(LocalTimeNoCheck(t)); |
| 460 } | 461 } |
| 461 | 462 |
| 462 | 463 |
| 463 function GetUTCFullYearFrom(aDate) { | 464 function GetUTCFullYearFrom(aDate) { |
| 464 var t = GetTimeFrom(aDate); | 465 var t = GetTimeFrom(aDate); |
| 465 if ($isNaN(t)) return t; | 466 if ($isNaN(t)) return t; |
| 466 return YearFromTime(t); | 467 return YearFromTime(t); |
| 467 } | 468 } |
| 468 | 469 |
| 469 | 470 |
| 470 function GetMonthFrom(aDate) { | 471 function GetMonthFrom(aDate) { |
| 471 var t = GetTimeFrom(aDate); | 472 var t = GetTimeFrom(aDate); |
| 472 if ($isNaN(t)) return t; | 473 if ($isNaN(t)) return t; |
| 473 return MonthFromTime(LocalTime(t)); | 474 return MonthFromTime(LocalTimeNoCheck(t)); |
| 474 } | 475 } |
| 475 | 476 |
| 476 | 477 |
| 477 function GetUTCMonthFrom(aDate) { | 478 function GetUTCMonthFrom(aDate) { |
| 478 var t = GetTimeFrom(aDate); | 479 var t = GetTimeFrom(aDate); |
| 479 if ($isNaN(t)) return t; | 480 if ($isNaN(t)) return t; |
| 480 return MonthFromTime(t); | 481 return MonthFromTime(t); |
| 481 } | 482 } |
| 482 | 483 |
| 483 | 484 |
| 484 function GetDateFrom(aDate) { | 485 function GetDateFrom(aDate) { |
| 485 var t = GetTimeFrom(aDate); | 486 var t = GetTimeFrom(aDate); |
| 486 if ($isNaN(t)) return t; | 487 if ($isNaN(t)) return t; |
| 487 return DateFromTime(LocalTime(t)); | 488 return DateFromTime(LocalTimeNoCheck(t)); |
| 488 } | 489 } |
| 489 | 490 |
| 490 | 491 |
| 491 function GetUTCDateFrom(aDate) { | 492 function GetUTCDateFrom(aDate) { |
| 492 var t = GetTimeFrom(aDate); | 493 var t = GetTimeFrom(aDate); |
| 493 if ($isNaN(t)) return t; | 494 if ($isNaN(t)) return t; |
| 494 return DateFromTime(t); | 495 return DateFromTime(t); |
| 495 } | 496 } |
| 496 | 497 |
| 497 | 498 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 519 function TimeString(time) { | 520 function TimeString(time) { |
| 520 return TwoDigitString(HourFromTime(time)) + ':' | 521 return TwoDigitString(HourFromTime(time)) + ':' |
| 521 + TwoDigitString(MinFromTime(time)) + ':' | 522 + TwoDigitString(MinFromTime(time)) + ':' |
| 522 + TwoDigitString(SecFromTime(time)); | 523 + TwoDigitString(SecFromTime(time)); |
| 523 } | 524 } |
| 524 | 525 |
| 525 | 526 |
| 526 function LocalTimezoneString(time) { | 527 function LocalTimezoneString(time) { |
| 527 var timezoneOffset = (local_time_offset + DaylightSavingsOffset(time)) / msPer
Minute; | 528 var timezoneOffset = (local_time_offset + DaylightSavingsOffset(time)) / msPer
Minute; |
| 528 var sign = (timezoneOffset >= 0) ? 1 : -1; | 529 var sign = (timezoneOffset >= 0) ? 1 : -1; |
| 529 var hours = $floor((sign * timezoneOffset)/60); | 530 var hours = FLOOR((sign * timezoneOffset)/60); |
| 530 var min = $floor((sign * timezoneOffset)%60); | 531 var min = FLOOR((sign * timezoneOffset)%60); |
| 531 var gmt = ' GMT' + ((sign == 1) ? '+' : '-') + TwoDigitString(hours) + TwoDigi
tString(min); | 532 var gmt = ' GMT' + ((sign == 1) ? '+' : '-') + TwoDigitString(hours) + TwoDigi
tString(min); |
| 532 return gmt + ' (' + LocalTimezone(time) + ')'; | 533 return gmt + ' (' + LocalTimezone(time) + ')'; |
| 533 } | 534 } |
| 534 | 535 |
| 535 | 536 |
| 536 function DatePrintString(time) { | 537 function DatePrintString(time) { |
| 537 return DateString(time) + ' ' + TimeString(time); | 538 return DateString(time) + ' ' + TimeString(time); |
| 538 } | 539 } |
| 539 | 540 |
| 540 // ------------------------------------------------------------------- | 541 // ------------------------------------------------------------------- |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 // elapsed since 1 January 1970 00:00:00 UTC. | 580 // elapsed since 1 January 1970 00:00:00 UTC. |
| 580 function DateNow() { | 581 function DateNow() { |
| 581 return %DateCurrentTime(); | 582 return %DateCurrentTime(); |
| 582 } | 583 } |
| 583 | 584 |
| 584 | 585 |
| 585 // ECMA 262 - 15.9.5.2 | 586 // ECMA 262 - 15.9.5.2 |
| 586 function DateToString() { | 587 function DateToString() { |
| 587 var t = GetTimeFrom(this); | 588 var t = GetTimeFrom(this); |
| 588 if ($isNaN(t)) return kInvalidDate; | 589 if ($isNaN(t)) return kInvalidDate; |
| 589 return DatePrintString(LocalTime(t)) + LocalTimezoneString(t); | 590 return DatePrintString(LocalTimeNoCheck(t)) + LocalTimezoneString(t); |
| 590 } | 591 } |
| 591 | 592 |
| 592 | 593 |
| 593 // ECMA 262 - 15.9.5.3 | 594 // ECMA 262 - 15.9.5.3 |
| 594 function DateToDateString() { | 595 function DateToDateString() { |
| 595 var t = GetTimeFrom(this); | 596 var t = GetTimeFrom(this); |
| 596 if ($isNaN(t)) return kInvalidDate; | 597 if ($isNaN(t)) return kInvalidDate; |
| 597 return DateString(LocalTime(t)); | 598 return DateString(LocalTimeNoCheck(t)); |
| 598 } | 599 } |
| 599 | 600 |
| 600 | 601 |
| 601 // ECMA 262 - 15.9.5.4 | 602 // ECMA 262 - 15.9.5.4 |
| 602 function DateToTimeString() { | 603 function DateToTimeString() { |
| 603 var t = GetTimeFrom(this); | 604 var t = GetTimeFrom(this); |
| 604 if ($isNaN(t)) return kInvalidDate; | 605 if ($isNaN(t)) return kInvalidDate; |
| 605 var lt = LocalTime(t); | 606 var lt = LocalTimeNoCheck(t); |
| 606 return TimeString(lt) + LocalTimezoneString(lt); | 607 return TimeString(lt) + LocalTimezoneString(lt); |
| 607 } | 608 } |
| 608 | 609 |
| 609 | 610 |
| 610 // ECMA 262 - 15.9.5.5 | 611 // ECMA 262 - 15.9.5.5 |
| 611 function DateToLocaleString() { | 612 function DateToLocaleString() { |
| 612 return DateToString.call(this); | 613 return DateToString.call(this); |
| 613 } | 614 } |
| 614 | 615 |
| 615 | 616 |
| 616 // ECMA 262 - 15.9.5.6 | 617 // ECMA 262 - 15.9.5.6 |
| 617 function DateToLocaleDateString() { | 618 function DateToLocaleDateString() { |
| 618 return DateToDateString.call(this); | 619 return DateToDateString.call(this); |
| 619 } | 620 } |
| 620 | 621 |
| 621 | 622 |
| 622 // ECMA 262 - 15.9.5.7 | 623 // ECMA 262 - 15.9.5.7 |
| 623 function DateToLocaleTimeString() { | 624 function DateToLocaleTimeString() { |
| 624 var t = GetTimeFrom(this); | 625 var t = GetTimeFrom(this); |
| 625 if ($isNaN(t)) return kInvalidDate; | 626 if ($isNaN(t)) return kInvalidDate; |
| 626 var lt = LocalTime(t); | 627 var lt = LocalTimeNoCheck(t); |
| 627 return TimeString(lt); | 628 return TimeString(lt); |
| 628 } | 629 } |
| 629 | 630 |
| 630 | 631 |
| 631 // ECMA 262 - 15.9.5.8 | 632 // ECMA 262 - 15.9.5.8 |
| 632 function DateValueOf() { | 633 function DateValueOf() { |
| 633 return GetTimeFrom(this); | 634 return GetTimeFrom(this); |
| 634 } | 635 } |
| 635 | 636 |
| 636 | 637 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 // ECMA 262 - 15.9.5.15 | 674 // ECMA 262 - 15.9.5.15 |
| 674 function DateGetUTCDate() { | 675 function DateGetUTCDate() { |
| 675 return GetUTCDateFrom(this); | 676 return GetUTCDateFrom(this); |
| 676 } | 677 } |
| 677 | 678 |
| 678 | 679 |
| 679 // ECMA 262 - 15.9.5.16 | 680 // ECMA 262 - 15.9.5.16 |
| 680 function DateGetDay() { | 681 function DateGetDay() { |
| 681 var t = GetTimeFrom(this); | 682 var t = GetTimeFrom(this); |
| 682 if ($isNaN(t)) return t; | 683 if ($isNaN(t)) return t; |
| 683 return WeekDay(LocalTime(t)); | 684 return WeekDay(LocalTimeNoCheck(t)); |
| 684 } | 685 } |
| 685 | 686 |
| 686 | 687 |
| 687 // ECMA 262 - 15.9.5.17 | 688 // ECMA 262 - 15.9.5.17 |
| 688 function DateGetUTCDay() { | 689 function DateGetUTCDay() { |
| 689 var t = GetTimeFrom(this); | 690 var t = GetTimeFrom(this); |
| 690 if ($isNaN(t)) return t; | 691 if ($isNaN(t)) return t; |
| 691 return WeekDay(t); | 692 return WeekDay(t); |
| 692 } | 693 } |
| 693 | 694 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 // ECMA 262 - 15.9.5.25 | 738 // ECMA 262 - 15.9.5.25 |
| 738 function DateGetUTCMilliseconds() { | 739 function DateGetUTCMilliseconds() { |
| 739 return GetUTCMillisecondsFrom(this); | 740 return GetUTCMillisecondsFrom(this); |
| 740 } | 741 } |
| 741 | 742 |
| 742 | 743 |
| 743 // ECMA 262 - 15.9.5.26 | 744 // ECMA 262 - 15.9.5.26 |
| 744 function DateGetTimezoneOffset() { | 745 function DateGetTimezoneOffset() { |
| 745 var t = GetTimeFrom(this); | 746 var t = GetTimeFrom(this); |
| 746 if ($isNaN(t)) return t; | 747 if ($isNaN(t)) return t; |
| 747 return (t - LocalTime(t)) / msPerMinute; | 748 return (t - LocalTimeNoCheck(t)) / msPerMinute; |
| 748 } | 749 } |
| 749 | 750 |
| 750 | 751 |
| 751 // ECMA 262 - 15.9.5.27 | 752 // ECMA 262 - 15.9.5.27 |
| 752 function DateSetTime(ms) { | 753 function DateSetTime(ms) { |
| 753 if (!IS_DATE(this)) throw new $TypeError('this is not a Date object.'); | 754 if (!IS_DATE(this)) throw new $TypeError('this is not a Date object.'); |
| 754 return %_SetValueOf(this, TimeClip(ToNumber(ms))); | 755 return %_SetValueOf(this, TimeClip(ToNumber(ms))); |
| 755 } | 756 } |
| 756 | 757 |
| 757 | 758 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 month = ToNumber(month); | 878 month = ToNumber(month); |
| 878 date = %_ArgumentsLength() < 2 ? GetUTCDateFrom(this) : ToNumber(date); | 879 date = %_ArgumentsLength() < 2 ? GetUTCDateFrom(this) : ToNumber(date); |
| 879 var day = MakeDay(YearFromTime(t), month, date); | 880 var day = MakeDay(YearFromTime(t), month, date); |
| 880 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); | 881 return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); |
| 881 } | 882 } |
| 882 | 883 |
| 883 | 884 |
| 884 // ECMA 262 - 15.9.5.40 | 885 // ECMA 262 - 15.9.5.40 |
| 885 function DateSetFullYear(year, month, date) { | 886 function DateSetFullYear(year, month, date) { |
| 886 var t = GetTimeFrom(this); | 887 var t = GetTimeFrom(this); |
| 887 t = $isNaN(t) ? 0 : LocalTime(t); | 888 t = $isNaN(t) ? 0 : LocalTimeNoCheck(t); |
| 888 year = ToNumber(year); | 889 year = ToNumber(year); |
| 889 var argc = %_ArgumentsLength(); | 890 var argc = %_ArgumentsLength(); |
| 890 month = argc < 2 ? MonthFromTime(t) : ToNumber(month); | 891 month = argc < 2 ? MonthFromTime(t) : ToNumber(month); |
| 891 date = argc < 3 ? DateFromTime(t) : ToNumber(date); | 892 date = argc < 3 ? DateFromTime(t) : ToNumber(date); |
| 892 var day = MakeDay(year, month, date); | 893 var day = MakeDay(year, month, date); |
| 893 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); | 894 return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); |
| 894 } | 895 } |
| 895 | 896 |
| 896 | 897 |
| 897 // ECMA 262 - 15.9.5.41 | 898 // ECMA 262 - 15.9.5.41 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 917 + Months[MonthFromTime(t)] + ' ' | 918 + Months[MonthFromTime(t)] + ' ' |
| 918 + YearFromTime(t) + ' ' | 919 + YearFromTime(t) + ' ' |
| 919 + TimeString(t) + ' GMT'; | 920 + TimeString(t) + ' GMT'; |
| 920 } | 921 } |
| 921 | 922 |
| 922 | 923 |
| 923 // ECMA 262 - B.2.4 | 924 // ECMA 262 - B.2.4 |
| 924 function DateGetYear() { | 925 function DateGetYear() { |
| 925 var t = GetTimeFrom(this); | 926 var t = GetTimeFrom(this); |
| 926 if ($isNaN(t)) return $NaN; | 927 if ($isNaN(t)) return $NaN; |
| 927 return YearFromTime(LocalTime(t)) - 1900; | 928 return YearFromTime(LocalTimeNoCheck(t)) - 1900; |
| 928 } | 929 } |
| 929 | 930 |
| 930 | 931 |
| 931 // ECMA 262 - B.2.5 | 932 // ECMA 262 - B.2.5 |
| 932 function DateSetYear(year) { | 933 function DateSetYear(year) { |
| 933 var t = LocalTime(GetTimeFrom(this)); | 934 var t = LocalTime(GetTimeFrom(this)); |
| 934 if ($isNaN(t)) t = 0; | 935 if ($isNaN(t)) t = 0; |
| 935 year = ToNumber(year); | 936 year = ToNumber(year); |
| 936 if ($isNaN(year)) return %_SetValueOf(this, $NaN); | 937 if ($isNaN(year)) return %_SetValueOf(this, $NaN); |
| 937 year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) | 938 year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 "setFullYear", DateSetFullYear, | 1011 "setFullYear", DateSetFullYear, |
| 1011 "setUTCFullYear", DateSetUTCFullYear, | 1012 "setUTCFullYear", DateSetUTCFullYear, |
| 1012 "toGMTString", DateToGMTString, | 1013 "toGMTString", DateToGMTString, |
| 1013 "toUTCString", DateToUTCString, | 1014 "toUTCString", DateToUTCString, |
| 1014 "getYear", DateGetYear, | 1015 "getYear", DateGetYear, |
| 1015 "setYear", DateSetYear | 1016 "setYear", DateSetYear |
| 1016 )); | 1017 )); |
| 1017 } | 1018 } |
| 1018 | 1019 |
| 1019 SetupDate(); | 1020 SetupDate(); |
| OLD | NEW |