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 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file relies on the fact that the following declarations have been made | 5 // This file relies on the fact that the following declarations have been made |
6 // in v8natives.js: | 6 // in v8natives.js: |
7 // var $isFinite = GlobalIsFinite; | 7 // var $isFinite = GlobalIsFinite; |
8 | 8 |
9 var $createDate; | 9 var $createDate; |
10 | 10 |
11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
12 | 12 |
13 (function(global, utils) { | 13 (function(global, shared, exports) { |
14 | 14 |
15 "use strict"; | 15 "use strict"; |
16 | 16 |
17 %CheckIsBootstrapping(); | 17 %CheckIsBootstrapping(); |
18 | 18 |
19 // ------------------------------------------------------------------- | 19 // ------------------------------------------------------------------- |
20 // Imports | 20 // Imports |
21 | 21 |
22 var GlobalDate = global.Date; | 22 var GlobalDate = global.Date; |
23 var InternalArray = utils.InternalArray; | 23 var InternalArray = shared.InternalArray; |
24 | |
25 var MathAbs; | |
26 var MathFloor; | |
27 | |
28 utils.Import(function(from) { | |
29 MathAbs = from.MathAbs; | |
30 MathFloor = from.MathFloor; | |
31 }); | |
32 | 24 |
33 // ------------------------------------------------------------------- | 25 // ------------------------------------------------------------------- |
34 | 26 |
35 // This file contains date support implemented in JavaScript. | 27 // This file contains date support implemented in JavaScript. |
36 | 28 |
37 var timezone_cache_time = NAN; | 29 var timezone_cache_time = NAN; |
38 var timezone_cache_timezone; | 30 var timezone_cache_timezone; |
39 | 31 |
40 function LocalTimezone(t) { | 32 function LocalTimezone(t) { |
41 if (NUMBER_IS_NAN(t)) return ""; | 33 if (NUMBER_IS_NAN(t)) return ""; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 94 |
103 | 95 |
104 // ECMA 262 - 15.9.1.13 | 96 // ECMA 262 - 15.9.1.13 |
105 function MakeDate(day, time) { | 97 function MakeDate(day, time) { |
106 var time = day * msPerDay + time; | 98 var time = day * msPerDay + time; |
107 // Some of our runtime funtions for computing UTC(time) rely on | 99 // Some of our runtime funtions for computing UTC(time) rely on |
108 // times not being significantly larger than MAX_TIME_MS. If there | 100 // times not being significantly larger than MAX_TIME_MS. If there |
109 // is no way that the time can be within range even after UTC | 101 // is no way that the time can be within range even after UTC |
110 // conversion we return NaN immediately instead of relying on | 102 // conversion we return NaN immediately instead of relying on |
111 // TimeClip to do it. | 103 // TimeClip to do it. |
112 if (MathAbs(time) > MAX_TIME_BEFORE_UTC) return NAN; | 104 if ($abs(time) > MAX_TIME_BEFORE_UTC) return NAN; |
113 return time; | 105 return time; |
114 } | 106 } |
115 | 107 |
116 | 108 |
117 // ECMA 262 - 15.9.1.14 | 109 // ECMA 262 - 15.9.1.14 |
118 function TimeClip(time) { | 110 function TimeClip(time) { |
119 if (!$isFinite(time)) return NAN; | 111 if (!$isFinite(time)) return NAN; |
120 if (MathAbs(time) > MAX_TIME_MS) return NAN; | 112 if ($abs(time) > MAX_TIME_MS) return NAN; |
121 return TO_INTEGER(time); | 113 return TO_INTEGER(time); |
122 } | 114 } |
123 | 115 |
124 | 116 |
125 // The Date cache is used to limit the cost of parsing the same Date | 117 // The Date cache is used to limit the cost of parsing the same Date |
126 // strings over and over again. | 118 // strings over and over again. |
127 var Date_cache = { | 119 var Date_cache = { |
128 // Cached time value. | 120 // Cached time value. |
129 time: 0, | 121 time: 0, |
130 // String input for which the cached time is valid. | 122 // String input for which the cached time is valid. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 + TwoDigitString(UTC_MIN(date)) + ':' | 229 + TwoDigitString(UTC_MIN(date)) + ':' |
238 + TwoDigitString(UTC_SEC(date)); | 230 + TwoDigitString(UTC_SEC(date)); |
239 } | 231 } |
240 | 232 |
241 | 233 |
242 function LocalTimezoneString(date) { | 234 function LocalTimezoneString(date) { |
243 var timezone = LocalTimezone(UTC_DATE_VALUE(date)); | 235 var timezone = LocalTimezone(UTC_DATE_VALUE(date)); |
244 | 236 |
245 var timezoneOffset = -TIMEZONE_OFFSET(date); | 237 var timezoneOffset = -TIMEZONE_OFFSET(date); |
246 var sign = (timezoneOffset >= 0) ? 1 : -1; | 238 var sign = (timezoneOffset >= 0) ? 1 : -1; |
247 var hours = MathFloor((sign * timezoneOffset)/60); | 239 var hours = $floor((sign * timezoneOffset)/60); |
248 var min = MathFloor((sign * timezoneOffset)%60); | 240 var min = $floor((sign * timezoneOffset)%60); |
249 var gmt = ' GMT' + ((sign == 1) ? '+' : '-') + | 241 var gmt = ' GMT' + ((sign == 1) ? '+' : '-') + |
250 TwoDigitString(hours) + TwoDigitString(min); | 242 TwoDigitString(hours) + TwoDigitString(min); |
251 return gmt + ' (' + timezone + ')'; | 243 return gmt + ' (' + timezone + ')'; |
252 } | 244 } |
253 | 245 |
254 | 246 |
255 function DatePrintString(date) { | 247 function DatePrintString(date) { |
256 return DateString(date) + ' ' + TimeString(date); | 248 return DateString(date) + ' ' + TimeString(date); |
257 } | 249 } |
258 | 250 |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 "getYear", DateGetYear, | 823 "getYear", DateGetYear, |
832 "setYear", DateSetYear, | 824 "setYear", DateSetYear, |
833 "toISOString", DateToISOString, | 825 "toISOString", DateToISOString, |
834 "toJSON", DateToJSON | 826 "toJSON", DateToJSON |
835 ]); | 827 ]); |
836 | 828 |
837 // Expose to the global scope. | 829 // Expose to the global scope. |
838 $createDate = CreateDate; | 830 $createDate = CreateDate; |
839 | 831 |
840 }) | 832 }) |
OLD | NEW |