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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 216 } |
217 | 217 |
218 var local_time_offset = %DateLocalTimeOffset(); | 218 var local_time_offset = %DateLocalTimeOffset(); |
219 | 219 |
220 function LocalTime(time) { | 220 function LocalTime(time) { |
221 if (NUMBER_IS_NAN(time)) return time; | 221 if (NUMBER_IS_NAN(time)) return time; |
222 return time + local_time_offset + DaylightSavingsOffset(time); | 222 return time + local_time_offset + DaylightSavingsOffset(time); |
223 } | 223 } |
224 | 224 |
225 function LocalTimeNoCheck(time) { | 225 function LocalTimeNoCheck(time) { |
| 226 if (time < -MAX_TIME_MS || time > MAX_TIME_MS) { |
| 227 return $NaN; |
| 228 } |
| 229 |
226 // Inline the DST offset cache checks for speed. | 230 // Inline the DST offset cache checks for speed. |
227 var cache = DST_offset_cache; | 231 var cache = DST_offset_cache; |
228 if (cache.start <= time && time <= cache.end) { | 232 if (cache.start <= time && time <= cache.end) { |
229 var dst_offset = cache.offset; | 233 var dst_offset = cache.offset; |
230 } else { | 234 } else { |
231 var dst_offset = DaylightSavingsOffset(time); | 235 var dst_offset = DaylightSavingsOffset(time); |
232 } | 236 } |
233 return time + local_time_offset + dst_offset; | 237 return time + local_time_offset + dst_offset; |
234 } | 238 } |
235 | 239 |
(...skipping 22 matching lines...) Expand all Loading... |
258 function TimeInYear(year) { | 262 function TimeInYear(year) { |
259 return DaysInYear(year) * msPerDay; | 263 return DaysInYear(year) * msPerDay; |
260 } | 264 } |
261 | 265 |
262 | 266 |
263 var ymd_from_time_cache = [$NaN, $NaN, $NaN]; | 267 var ymd_from_time_cache = [$NaN, $NaN, $NaN]; |
264 var ymd_from_time_cached_time = $NaN; | 268 var ymd_from_time_cached_time = $NaN; |
265 | 269 |
266 function YearFromTime(t) { | 270 function YearFromTime(t) { |
267 if (t !== ymd_from_time_cached_time) { | 271 if (t !== ymd_from_time_cached_time) { |
268 // Limits according to ECMA 262 15.9.1.1 | 272 if (!$isFinite(t)) { |
269 if (!$isFinite(t) || t < -8640000000000000 || t > 8640000000000000) { | |
270 return $NaN; | 273 return $NaN; |
271 } | 274 } |
272 | 275 |
273 %DateYMDFromTime(t, ymd_from_time_cache); | 276 %DateYMDFromTime(t, ymd_from_time_cache); |
274 ymd_from_time_cached_time = t | 277 ymd_from_time_cached_time = t |
275 } | 278 } |
276 | 279 |
277 return ymd_from_time_cache[0]; | 280 return ymd_from_time_cache[0]; |
278 } | 281 } |
279 | 282 |
280 function MonthFromTime(t) { | 283 function MonthFromTime(t) { |
281 if (t !== ymd_from_time_cached_time) { | 284 if (t !== ymd_from_time_cached_time) { |
282 // Limits according to ECMA 262 15.9.1.1 | 285 if (!$isFinite(t)) { |
283 if (!$isFinite(t) || t < -8640000000000000 || t > 8640000000000000) { | |
284 return $NaN; | 286 return $NaN; |
285 } | 287 } |
286 %DateYMDFromTime(t, ymd_from_time_cache); | 288 %DateYMDFromTime(t, ymd_from_time_cache); |
287 ymd_from_time_cached_time = t | 289 ymd_from_time_cached_time = t |
288 } | 290 } |
289 | 291 |
290 return ymd_from_time_cache[1]; | 292 return ymd_from_time_cache[1]; |
291 } | 293 } |
292 | 294 |
293 function DateFromTime(t) { | 295 function DateFromTime(t) { |
294 if (t !== ymd_from_time_cached_time) { | 296 if (t !== ymd_from_time_cached_time) { |
295 // Limits according to ECMA 262 15.9.1.1 | 297 if (!$isFinite(t)) { |
296 if (!$isFinite(t) || t < -8640000000000000 || t > 8640000000000000) { | |
297 return $NaN; | 298 return $NaN; |
298 } | 299 } |
299 | 300 |
300 %DateYMDFromTime(t, ymd_from_time_cache); | 301 %DateYMDFromTime(t, ymd_from_time_cache); |
301 ymd_from_time_cached_time = t | 302 ymd_from_time_cached_time = t |
302 } | 303 } |
303 | 304 |
304 return ymd_from_time_cache[2]; | 305 return ymd_from_time_cache[2]; |
305 } | 306 } |
306 | 307 |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 "toGMTString", DateToGMTString, | 1081 "toGMTString", DateToGMTString, |
1081 "toUTCString", DateToUTCString, | 1082 "toUTCString", DateToUTCString, |
1082 "getYear", DateGetYear, | 1083 "getYear", DateGetYear, |
1083 "setYear", DateSetYear, | 1084 "setYear", DateSetYear, |
1084 "toISOString", DateToISOString, | 1085 "toISOString", DateToISOString, |
1085 "toJSON", DateToJSON | 1086 "toJSON", DateToJSON |
1086 )); | 1087 )); |
1087 } | 1088 } |
1088 | 1089 |
1089 SetupDate(); | 1090 SetupDate(); |
OLD | NEW |