ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 29 | // This file relies on the fact that the following declarations have been made |
| 30 | // in v8natives.js: |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 31 | // const $isFinite = GlobalIsFinite; |
| 32 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 33 | // ------------------------------------------------------------------- |
| 34 | |
| 35 | // This file contains date support implemented in JavaScript. |
| 36 | |
| 37 | |
| 38 | // Keep reference to original values of some global properties. This |
| 39 | // has the added benefit that the code in this file is isolated from |
| 40 | // changes to these properties. |
| 41 | const $Date = global.Date; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 43 | // Helper function to throw error. |
| 44 | function ThrowDateTypeError() { |
| 45 | throw new $TypeError('this is not a Date object.'); |
| 46 | } |
| 47 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | // ECMA 262 - 5.2 |
| 49 | function Modulo(value, remainder) { |
| 50 | var mod = value % remainder; |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 51 | // Guard against returning -0. |
| 52 | if (mod == 0) return 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 53 | return mod >= 0 ? mod : mod + remainder; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 54 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | |
| 56 | |
| 57 | function TimeWithinDay(time) { |
| 58 | return Modulo(time, msPerDay); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 59 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 60 | |
| 61 | |
| 62 | // ECMA 262 - 15.9.1.3 |
| 63 | function DaysInYear(year) { |
| 64 | if (year % 4 != 0) return 365; |
| 65 | if ((year % 100 == 0) && (year % 400 != 0)) return 365; |
| 66 | return 366; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 67 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 68 | |
| 69 | |
| 70 | function DayFromYear(year) { |
| 71 | return 365 * (year-1970) |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 72 | + FLOOR((year-1969)/4) |
| 73 | - FLOOR((year-1901)/100) |
| 74 | + FLOOR((year-1601)/400); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 75 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 76 | |
| 77 | |
| 78 | function TimeFromYear(year) { |
| 79 | return msPerDay * DayFromYear(year); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 80 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 81 | |
| 82 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 83 | function InLeapYear(time) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 84 | return DaysInYear(YearFromTime(time)) - 365; // Returns 1 or 0. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 85 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 86 | |
| 87 | |
| 88 | // ECMA 262 - 15.9.1.9 |
| 89 | function EquivalentYear(year) { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 90 | // Returns an equivalent year in the range [2008-2035] matching |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 91 | // - leap year. |
| 92 | // - week day of first day. |
| 93 | var time = TimeFromYear(year); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 94 | var recent_year = (InLeapYear(time) == 0 ? 1967 : 1956) + |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 95 | (WeekDay(time) * 12) % 28; |
| 96 | // Find the year in the range 2008..2037 that is equivalent mod 28. |
| 97 | // Add 3*28 to give a positive argument to the modulus operator. |
| 98 | return 2008 + (recent_year + 3*28 - 2008) % 28; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 99 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 100 | |
| 101 | |
| 102 | function EquivalentTime(t) { |
| 103 | // The issue here is that some library calls don't work right for dates |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 104 | // that cannot be represented using a non-negative signed 32 bit integer |
| 105 | // (measured in whole seconds based on the 1970 epoch). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 106 | // We solve this by mapping the time to a year with same leap-year-ness |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 107 | // and same starting day for the year. The ECMAscript specification says |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 108 | // we must do this, but for compatibility with other browsers, we use |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 109 | // the actual year if it is in the range 1970..2037 |
| 110 | if (t >= 0 && t <= 2.1e12) return t; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 111 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 112 | var day = MakeDay(EquivalentYear(YearFromTime(t)), |
| 113 | MonthFromTime(t), |
| 114 | DateFromTime(t)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 115 | return MakeDate(day, TimeWithinDay(t)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 116 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 117 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 118 | |
whesse@chromium.org | 421a0f4 | 2010-03-30 15:09:23 +0000 | [diff] [blame] | 119 | // local_time_offset is initialized when the DST_offset_cache is missed. |
| 120 | // It must not be used until after a call to DaylightSavingsOffset(). |
| 121 | // In this way, only one check, for a DST cache miss, is needed. |
| 122 | var local_time_offset; |
| 123 | |
| 124 | |
| 125 | // Because computing the DST offset is an expensive operation, |
| 126 | // we keep a cache of the last computed DST offset along with a time interval |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 127 | // where we know the cache is valid. |
whesse@chromium.org | 421a0f4 | 2010-03-30 15:09:23 +0000 | [diff] [blame] | 128 | // When the cache is valid, local_time_offset is also valid. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 129 | var DST_offset_cache = { |
| 130 | // Cached DST offset. |
| 131 | offset: 0, |
| 132 | // Time interval where the cached offset is valid. |
| 133 | start: 0, end: -1, |
| 134 | // Size of next interval expansion. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 135 | increment: 0, |
| 136 | initial_increment: 19 * msPerDay |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 139 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 140 | // NOTE: The implementation relies on the fact that no time zones have |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 141 | // more than one daylight savings offset change per 19 days. |
| 142 | // |
| 143 | // In Egypt in 2010 they decided to suspend DST during Ramadan. This |
| 144 | // led to a short interval where DST is in effect from September 10 to |
| 145 | // September 30. |
| 146 | // |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 147 | // If this function is called with NaN it returns NaN. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 148 | function DaylightSavingsOffset(t) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 149 | // Load the cache object from the builtins object. |
| 150 | var cache = DST_offset_cache; |
| 151 | |
| 152 | // Cache the start and the end in local variables for fast access. |
| 153 | var start = cache.start; |
| 154 | var end = cache.end; |
| 155 | |
| 156 | if (start <= t) { |
| 157 | // If the time fits in the cached interval, return the cached offset. |
| 158 | if (t <= end) return cache.offset; |
| 159 | |
whesse@chromium.org | 421a0f4 | 2010-03-30 15:09:23 +0000 | [diff] [blame] | 160 | // If the cache misses, the local_time_offset may not be initialized. |
| 161 | if (IS_UNDEFINED(local_time_offset)) { |
| 162 | local_time_offset = %DateLocalTimeOffset(); |
| 163 | } |
| 164 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 165 | // Compute a possible new interval end. |
| 166 | var new_end = end + cache.increment; |
| 167 | |
| 168 | if (t <= new_end) { |
| 169 | var end_offset = %DateDaylightSavingsOffset(EquivalentTime(new_end)); |
| 170 | if (cache.offset == end_offset) { |
| 171 | // If the offset at the end of the new interval still matches |
| 172 | // the offset in the cache, we grow the cached time interval |
| 173 | // and return the offset. |
| 174 | cache.end = new_end; |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 175 | cache.increment = cache.initial_increment; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 176 | return end_offset; |
| 177 | } else { |
| 178 | var offset = %DateDaylightSavingsOffset(EquivalentTime(t)); |
| 179 | if (offset == end_offset) { |
| 180 | // The offset at the given time is equal to the offset at the |
| 181 | // new end of the interval, so that means that we've just skipped |
| 182 | // the point in time where the DST offset change occurred. Updated |
| 183 | // the interval to reflect this and reset the increment. |
| 184 | cache.start = t; |
| 185 | cache.end = new_end; |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 186 | cache.increment = cache.initial_increment; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 187 | } else { |
| 188 | // The interval contains a DST offset change and the given time is |
| 189 | // before it. Adjust the increment to avoid a linear search for |
| 190 | // the offset change point and change the end of the interval. |
| 191 | cache.increment /= 3; |
| 192 | cache.end = t; |
| 193 | } |
| 194 | // Update the offset in the cache and return it. |
| 195 | cache.offset = offset; |
| 196 | return offset; |
| 197 | } |
| 198 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 199 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 200 | |
whesse@chromium.org | 421a0f4 | 2010-03-30 15:09:23 +0000 | [diff] [blame] | 201 | // If the cache misses, the local_time_offset may not be initialized. |
| 202 | if (IS_UNDEFINED(local_time_offset)) { |
| 203 | local_time_offset = %DateLocalTimeOffset(); |
| 204 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 205 | // Compute the DST offset for the time and shrink the cache interval |
| 206 | // to only contain the time. This allows fast repeated DST offset |
| 207 | // computations for the same time. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 208 | var offset = %DateDaylightSavingsOffset(EquivalentTime(t)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 209 | cache.offset = offset; |
| 210 | cache.start = cache.end = t; |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 211 | cache.increment = cache.initial_increment; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 212 | return offset; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 213 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 214 | |
| 215 | |
| 216 | var timezone_cache_time = $NaN; |
| 217 | var timezone_cache_timezone; |
| 218 | |
| 219 | function LocalTimezone(t) { |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 220 | if (NUMBER_IS_NAN(t)) return ""; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 221 | if (t == timezone_cache_time) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 222 | return timezone_cache_timezone; |
| 223 | } |
| 224 | var timezone = %DateLocalTimezone(EquivalentTime(t)); |
| 225 | timezone_cache_time = t; |
| 226 | timezone_cache_timezone = timezone; |
| 227 | return timezone; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 228 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 229 | |
| 230 | |
| 231 | function WeekDay(time) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 232 | return Modulo(DAY(time) + 4, 7); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 233 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 234 | |
| 235 | |
| 236 | function LocalTime(time) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 237 | if (NUMBER_IS_NAN(time)) return time; |
whesse@chromium.org | 421a0f4 | 2010-03-30 15:09:23 +0000 | [diff] [blame] | 238 | // DaylightSavingsOffset called before local_time_offset used. |
| 239 | return time + DaylightSavingsOffset(time) + local_time_offset; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 240 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 241 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 242 | |
| 243 | var ltcache = { |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 244 | key: null, |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 245 | val: null |
| 246 | }; |
| 247 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 248 | function LocalTimeNoCheck(time) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 249 | var ltc = ltcache; |
| 250 | if (%_ObjectEquals(time, ltc.key)) return ltc.val; |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 251 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 252 | // Inline the DST offset cache checks for speed. |
whesse@chromium.org | 421a0f4 | 2010-03-30 15:09:23 +0000 | [diff] [blame] | 253 | // The cache is hit, or DaylightSavingsOffset is called, |
| 254 | // before local_time_offset is used. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 255 | var cache = DST_offset_cache; |
| 256 | if (cache.start <= time && time <= cache.end) { |
| 257 | var dst_offset = cache.offset; |
| 258 | } else { |
| 259 | var dst_offset = DaylightSavingsOffset(time); |
| 260 | } |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 261 | ltc.key = time; |
| 262 | return (ltc.val = time + local_time_offset + dst_offset); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 263 | } |
| 264 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 265 | |
| 266 | function UTC(time) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 267 | if (NUMBER_IS_NAN(time)) return time; |
whesse@chromium.org | 421a0f4 | 2010-03-30 15:09:23 +0000 | [diff] [blame] | 268 | // local_time_offset is needed before the call to DaylightSavingsOffset, |
| 269 | // so it may be uninitialized. |
| 270 | if (IS_UNDEFINED(local_time_offset)) { |
| 271 | local_time_offset = %DateLocalTimeOffset(); |
| 272 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 273 | var tmp = time - local_time_offset; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 274 | return tmp - DaylightSavingsOffset(tmp); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 275 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 276 | |
| 277 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 278 | // ECMA 262 - 15.9.1.11 |
| 279 | function MakeTime(hour, min, sec, ms) { |
| 280 | if (!$isFinite(hour)) return $NaN; |
| 281 | if (!$isFinite(min)) return $NaN; |
| 282 | if (!$isFinite(sec)) return $NaN; |
| 283 | if (!$isFinite(ms)) return $NaN; |
| 284 | return TO_INTEGER(hour) * msPerHour |
| 285 | + TO_INTEGER(min) * msPerMinute |
| 286 | + TO_INTEGER(sec) * msPerSecond |
| 287 | + TO_INTEGER(ms); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 288 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 289 | |
| 290 | |
| 291 | // ECMA 262 - 15.9.1.12 |
| 292 | function TimeInYear(year) { |
| 293 | return DaysInYear(year) * msPerDay; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 294 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 295 | |
| 296 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 297 | var ymd_from_time_cache = [$NaN, $NaN, $NaN]; |
| 298 | var ymd_from_time_cached_time = $NaN; |
| 299 | |
| 300 | function YearFromTime(t) { |
| 301 | if (t !== ymd_from_time_cached_time) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 302 | if (!$isFinite(t)) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 303 | return $NaN; |
| 304 | } |
| 305 | |
| 306 | %DateYMDFromTime(t, ymd_from_time_cache); |
| 307 | ymd_from_time_cached_time = t |
| 308 | } |
| 309 | |
| 310 | return ymd_from_time_cache[0]; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 311 | } |
| 312 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 313 | function MonthFromTime(t) { |
| 314 | if (t !== ymd_from_time_cached_time) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 315 | if (!$isFinite(t)) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 316 | return $NaN; |
| 317 | } |
| 318 | %DateYMDFromTime(t, ymd_from_time_cache); |
| 319 | ymd_from_time_cached_time = t |
| 320 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 321 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 322 | return ymd_from_time_cache[1]; |
| 323 | } |
| 324 | |
| 325 | function DateFromTime(t) { |
| 326 | if (t !== ymd_from_time_cached_time) { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 327 | if (!$isFinite(t)) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 328 | return $NaN; |
| 329 | } |
| 330 | |
| 331 | %DateYMDFromTime(t, ymd_from_time_cache); |
| 332 | ymd_from_time_cached_time = t |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 333 | } |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 334 | |
| 335 | return ymd_from_time_cache[2]; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 336 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 338 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 339 | // Compute number of days given a year, month, date. |
| 340 | // Note that month and date can lie outside the normal range. |
| 341 | // For example: |
| 342 | // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20) |
| 343 | // MakeDay(2007, -33, 1) --> MakeDay(2004, 3, 1) |
| 344 | // MakeDay(2007, 14, -50) --> MakeDay(2007, 8, 11) |
| 345 | function MakeDay(year, month, date) { |
| 346 | if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) return $NaN; |
| 347 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 348 | // Convert to integer and map -0 to 0. |
| 349 | year = TO_INTEGER_MAP_MINUS_ZERO(year); |
| 350 | month = TO_INTEGER_MAP_MINUS_ZERO(month); |
| 351 | date = TO_INTEGER_MAP_MINUS_ZERO(date); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 352 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 353 | if (year < kMinYear || year > kMaxYear || |
| 354 | month < kMinMonth || month > kMaxMonth || |
| 355 | date < kMinDate || date > kMaxDate) { |
| 356 | return $NaN; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 357 | } |
| 358 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 359 | // Now we rely on year, month and date being SMIs. |
| 360 | return %DateMakeDay(year, month, date); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 361 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 362 | |
| 363 | |
| 364 | // ECMA 262 - 15.9.1.13 |
| 365 | function MakeDate(day, time) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 366 | var time = day * msPerDay + time; |
| 367 | // Some of our runtime funtions for computing UTC(time) rely on |
| 368 | // times not being significantly larger than MAX_TIME_MS. If there |
| 369 | // is no way that the time can be within range even after UTC |
| 370 | // conversion we return NaN immediately instead of relying on |
| 371 | // TimeClip to do it. |
| 372 | if ($abs(time) > MAX_TIME_BEFORE_UTC) return $NaN; |
| 373 | return time; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 374 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 375 | |
| 376 | |
| 377 | // ECMA 262 - 15.9.1.14 |
| 378 | function TimeClip(time) { |
| 379 | if (!$isFinite(time)) return $NaN; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 380 | if ($abs(time) > MAX_TIME_MS) return $NaN; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 381 | return TO_INTEGER(time); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 382 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 383 | |
| 384 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 385 | // The Date cache is used to limit the cost of parsing the same Date |
| 386 | // strings over and over again. |
| 387 | var Date_cache = { |
| 388 | // Cached time value. |
| 389 | time: $NaN, |
| 390 | // Cached year when interpreting the time as a local time. Only |
| 391 | // valid when the time matches cached time. |
| 392 | year: $NaN, |
| 393 | // String input for which the cached time is valid. |
| 394 | string: null |
| 395 | }; |
| 396 | |
| 397 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 398 | %SetCode($Date, function(year, month, date, hours, minutes, seconds, ms) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 399 | if (!%_IsConstructCall()) { |
| 400 | // ECMA 262 - 15.9.2 |
| 401 | return (new $Date()).toString(); |
| 402 | } |
| 403 | |
| 404 | // ECMA 262 - 15.9.3 |
| 405 | var argc = %_ArgumentsLength(); |
| 406 | var value; |
| 407 | if (argc == 0) { |
| 408 | value = %DateCurrentTime(); |
| 409 | |
| 410 | } else if (argc == 1) { |
| 411 | if (IS_NUMBER(year)) { |
| 412 | value = TimeClip(year); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 413 | |
| 414 | } else if (IS_STRING(year)) { |
| 415 | // Probe the Date cache. If we already have a time value for the |
| 416 | // given time, we re-use that instead of parsing the string again. |
| 417 | var cache = Date_cache; |
| 418 | if (cache.string === year) { |
| 419 | value = cache.time; |
| 420 | } else { |
| 421 | value = DateParse(year); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 422 | if (!NUMBER_IS_NAN(value)) { |
| 423 | cache.time = value; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 424 | cache.year = YearFromTime(LocalTimeNoCheck(value)); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 425 | cache.string = year; |
| 426 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 427 | } |
| 428 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 429 | } else { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 430 | // According to ECMA 262, no hint should be given for this |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 431 | // conversion. However, ToPrimitive defaults to STRING_HINT for |
| 432 | // Date objects which will lose precision when the Date |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | // constructor is called with another Date object as its |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 434 | // argument. We therefore use NUMBER_HINT for the conversion, |
| 435 | // which is the default for everything else than Date objects. |
| 436 | // This makes us behave like KJS and SpiderMonkey. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 437 | var time = ToPrimitive(year, NUMBER_HINT); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 438 | value = IS_STRING(time) ? DateParse(time) : TimeClip(ToNumber(time)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 439 | } |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 440 | |
| 441 | } else { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 442 | year = ToNumber(year); |
| 443 | month = ToNumber(month); |
| 444 | date = argc > 2 ? ToNumber(date) : 1; |
| 445 | hours = argc > 3 ? ToNumber(hours) : 0; |
| 446 | minutes = argc > 4 ? ToNumber(minutes) : 0; |
| 447 | seconds = argc > 5 ? ToNumber(seconds) : 0; |
| 448 | ms = argc > 6 ? ToNumber(ms) : 0; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 449 | year = (!NUMBER_IS_NAN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 450 | ? 1900 + TO_INTEGER(year) : year; |
| 451 | var day = MakeDay(year, month, date); |
| 452 | var time = MakeTime(hours, minutes, seconds, ms); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 453 | value = TimeClip(UTC(MakeDate(day, time))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 454 | } |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 455 | %_SetValueOf(this, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 456 | }); |
| 457 | |
| 458 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 459 | %FunctionSetPrototype($Date, new $Date($NaN)); |
| 460 | |
| 461 | |
| 462 | var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; |
| 463 | var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; |
| 464 | |
| 465 | |
| 466 | function TwoDigitString(value) { |
| 467 | return value < 10 ? "0" + value : "" + value; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 468 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 469 | |
| 470 | |
| 471 | function DateString(time) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 472 | return WeekDays[WeekDay(time)] + ' ' |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 473 | + Months[MonthFromTime(time)] + ' ' |
| 474 | + TwoDigitString(DateFromTime(time)) + ' ' |
| 475 | + YearFromTime(time); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 476 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 477 | |
| 478 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 479 | var LongWeekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; |
| 480 | var LongMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; |
| 481 | |
| 482 | |
| 483 | function LongDateString(time) { |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 484 | return LongWeekDays[WeekDay(time)] + ', ' |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 485 | + LongMonths[MonthFromTime(time)] + ' ' |
| 486 | + TwoDigitString(DateFromTime(time)) + ', ' |
| 487 | + YearFromTime(time); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 491 | function TimeString(time) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 492 | return TwoDigitString(HOUR_FROM_TIME(time)) + ':' |
| 493 | + TwoDigitString(MIN_FROM_TIME(time)) + ':' |
| 494 | + TwoDigitString(SEC_FROM_TIME(time)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 495 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 496 | |
| 497 | |
| 498 | function LocalTimezoneString(time) { |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 499 | var old_timezone = timezone_cache_timezone; |
| 500 | var timezone = LocalTimezone(time); |
| 501 | if (old_timezone && timezone != old_timezone) { |
| 502 | // If the timezone string has changed from the one that we cached, |
| 503 | // the local time offset may now be wrong. So we need to update it |
| 504 | // and try again. |
| 505 | local_time_offset = %DateLocalTimeOffset(); |
| 506 | // We also need to invalidate the DST cache as the new timezone may have |
| 507 | // different DST times. |
| 508 | var dst_cache = DST_offset_cache; |
| 509 | dst_cache.start = 0; |
| 510 | dst_cache.end = -1; |
| 511 | } |
| 512 | |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 513 | var timezoneOffset = |
whesse@chromium.org | 421a0f4 | 2010-03-30 15:09:23 +0000 | [diff] [blame] | 514 | (DaylightSavingsOffset(time) + local_time_offset) / msPerMinute; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 515 | var sign = (timezoneOffset >= 0) ? 1 : -1; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 516 | var hours = FLOOR((sign * timezoneOffset)/60); |
| 517 | var min = FLOOR((sign * timezoneOffset)%60); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 518 | var gmt = ' GMT' + ((sign == 1) ? '+' : '-') + |
| 519 | TwoDigitString(hours) + TwoDigitString(min); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 520 | return gmt + ' (' + timezone + ')'; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 521 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 522 | |
| 523 | |
| 524 | function DatePrintString(time) { |
| 525 | return DateString(time) + ' ' + TimeString(time); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 526 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 527 | |
| 528 | // ------------------------------------------------------------------- |
| 529 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 530 | // Reused output buffer. Used when parsing date strings. |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 531 | var parse_buffer = $Array(8); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 532 | |
| 533 | // ECMA 262 - 15.9.4.2 |
| 534 | function DateParse(string) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 535 | var arr = %DateParseString(ToString(string), parse_buffer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 536 | if (IS_NULL(arr)) return $NaN; |
| 537 | |
| 538 | var day = MakeDay(arr[0], arr[1], arr[2]); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 539 | var time = MakeTime(arr[3], arr[4], arr[5], arr[6]); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 540 | var date = MakeDate(day, time); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 541 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 542 | if (IS_NULL(arr[7])) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 543 | return TimeClip(UTC(date)); |
| 544 | } else { |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 545 | return TimeClip(date - arr[7] * 1000); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 546 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 547 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 548 | |
| 549 | |
| 550 | // ECMA 262 - 15.9.4.3 |
| 551 | function DateUTC(year, month, date, hours, minutes, seconds, ms) { |
| 552 | year = ToNumber(year); |
| 553 | month = ToNumber(month); |
| 554 | var argc = %_ArgumentsLength(); |
| 555 | date = argc > 2 ? ToNumber(date) : 1; |
| 556 | hours = argc > 3 ? ToNumber(hours) : 0; |
| 557 | minutes = argc > 4 ? ToNumber(minutes) : 0; |
| 558 | seconds = argc > 5 ? ToNumber(seconds) : 0; |
| 559 | ms = argc > 6 ? ToNumber(ms) : 0; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 560 | year = (!NUMBER_IS_NAN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 561 | ? 1900 + TO_INTEGER(year) : year; |
| 562 | var day = MakeDay(year, month, date); |
| 563 | var time = MakeTime(hours, minutes, seconds, ms); |
| 564 | return %_SetValueOf(this, TimeClip(MakeDate(day, time))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 565 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 566 | |
| 567 | |
| 568 | // Mozilla-specific extension. Returns the number of milliseconds |
| 569 | // elapsed since 1 January 1970 00:00:00 UTC. |
| 570 | function DateNow() { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 571 | return %DateCurrentTime(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 572 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 573 | |
| 574 | |
| 575 | // ECMA 262 - 15.9.5.2 |
| 576 | function DateToString() { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 577 | var t = DATE_VALUE(this); |
| 578 | if (NUMBER_IS_NAN(t)) return kInvalidDate; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 579 | var time_zone_string = LocalTimezoneString(t); // May update local offset. |
| 580 | return DatePrintString(LocalTimeNoCheck(t)) + time_zone_string; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 581 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 582 | |
| 583 | |
| 584 | // ECMA 262 - 15.9.5.3 |
| 585 | function DateToDateString() { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 586 | var t = DATE_VALUE(this); |
| 587 | if (NUMBER_IS_NAN(t)) return kInvalidDate; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 588 | return DateString(LocalTimeNoCheck(t)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 589 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 590 | |
| 591 | |
| 592 | // ECMA 262 - 15.9.5.4 |
| 593 | function DateToTimeString() { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 594 | var t = DATE_VALUE(this); |
| 595 | if (NUMBER_IS_NAN(t)) return kInvalidDate; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 596 | var time_zone_string = LocalTimezoneString(t); // May update local offset. |
| 597 | return TimeString(LocalTimeNoCheck(t)) + time_zone_string; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | |
| 601 | // ECMA 262 - 15.9.5.5 |
| 602 | function DateToLocaleString() { |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 603 | return %_CallFunction(this, DateToString); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | |
| 607 | // ECMA 262 - 15.9.5.6 |
| 608 | function DateToLocaleDateString() { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 609 | var t = DATE_VALUE(this); |
| 610 | if (NUMBER_IS_NAN(t)) return kInvalidDate; |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 611 | return LongDateString(LocalTimeNoCheck(t)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 612 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 613 | |
| 614 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 615 | // ECMA 262 - 15.9.5.7 |
| 616 | function DateToLocaleTimeString() { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 617 | var t = DATE_VALUE(this); |
| 618 | if (NUMBER_IS_NAN(t)) return kInvalidDate; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 619 | var lt = LocalTimeNoCheck(t); |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 620 | return TimeString(lt); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | |
| 624 | // ECMA 262 - 15.9.5.8 |
| 625 | function DateValueOf() { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 626 | return DATE_VALUE(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 627 | } |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 628 | |
| 629 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 630 | // ECMA 262 - 15.9.5.9 |
| 631 | function DateGetTime() { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 632 | return DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | |
| 636 | // ECMA 262 - 15.9.5.10 |
| 637 | function DateGetFullYear() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 638 | var t = DATE_VALUE(this); |
| 639 | if (NUMBER_IS_NAN(t)) return t; |
| 640 | var cache = Date_cache; |
| 641 | if (cache.time === t) return cache.year; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 642 | return YearFromTime(LocalTimeNoCheck(t)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 643 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 644 | |
| 645 | |
| 646 | // ECMA 262 - 15.9.5.11 |
| 647 | function DateGetUTCFullYear() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 648 | var t = DATE_VALUE(this); |
| 649 | if (NUMBER_IS_NAN(t)) return t; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 650 | return YearFromTime(t); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 651 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 652 | |
| 653 | |
| 654 | // ECMA 262 - 15.9.5.12 |
| 655 | function DateGetMonth() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 656 | var t = DATE_VALUE(this); |
| 657 | if (NUMBER_IS_NAN(t)) return t; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 658 | return MonthFromTime(LocalTimeNoCheck(t)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 659 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 660 | |
| 661 | |
| 662 | // ECMA 262 - 15.9.5.13 |
| 663 | function DateGetUTCMonth() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 664 | var t = DATE_VALUE(this); |
| 665 | if (NUMBER_IS_NAN(t)) return t; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 666 | return MonthFromTime(t); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 667 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 668 | |
| 669 | |
| 670 | // ECMA 262 - 15.9.5.14 |
| 671 | function DateGetDate() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 672 | var t = DATE_VALUE(this); |
| 673 | if (NUMBER_IS_NAN(t)) return t; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 674 | return DateFromTime(LocalTimeNoCheck(t)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 675 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 676 | |
| 677 | |
| 678 | // ECMA 262 - 15.9.5.15 |
| 679 | function DateGetUTCDate() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 680 | var t = DATE_VALUE(this); |
| 681 | return NAN_OR_DATE_FROM_TIME(t); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 682 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 683 | |
| 684 | |
| 685 | // ECMA 262 - 15.9.5.16 |
| 686 | function DateGetDay() { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 687 | var t = DATE_VALUE(this); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 688 | if (NUMBER_IS_NAN(t)) return t; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 689 | return WeekDay(LocalTimeNoCheck(t)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 690 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 691 | |
| 692 | |
| 693 | // ECMA 262 - 15.9.5.17 |
| 694 | function DateGetUTCDay() { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 695 | var t = DATE_VALUE(this); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 696 | if (NUMBER_IS_NAN(t)) return t; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 697 | return WeekDay(t); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 698 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 699 | |
| 700 | |
| 701 | // ECMA 262 - 15.9.5.18 |
| 702 | function DateGetHours() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 703 | var t = DATE_VALUE(this); |
| 704 | if (NUMBER_IS_NAN(t)) return t; |
| 705 | return HOUR_FROM_TIME(LocalTimeNoCheck(t)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 706 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 707 | |
| 708 | |
| 709 | // ECMA 262 - 15.9.5.19 |
| 710 | function DateGetUTCHours() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 711 | var t = DATE_VALUE(this); |
| 712 | if (NUMBER_IS_NAN(t)) return t; |
| 713 | return HOUR_FROM_TIME(t); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 714 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 715 | |
| 716 | |
| 717 | // ECMA 262 - 15.9.5.20 |
| 718 | function DateGetMinutes() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 719 | var t = DATE_VALUE(this); |
| 720 | if (NUMBER_IS_NAN(t)) return t; |
| 721 | return MIN_FROM_TIME(LocalTimeNoCheck(t)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 722 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 723 | |
| 724 | |
| 725 | // ECMA 262 - 15.9.5.21 |
| 726 | function DateGetUTCMinutes() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 727 | var t = DATE_VALUE(this); |
| 728 | return NAN_OR_MIN_FROM_TIME(t); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 729 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 730 | |
| 731 | |
| 732 | // ECMA 262 - 15.9.5.22 |
| 733 | function DateGetSeconds() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 734 | var t = DATE_VALUE(this); |
| 735 | if (NUMBER_IS_NAN(t)) return t; |
| 736 | return SEC_FROM_TIME(LocalTimeNoCheck(t)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 737 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 738 | |
| 739 | |
| 740 | // ECMA 262 - 15.9.5.23 |
| 741 | function DateGetUTCSeconds() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 742 | var t = DATE_VALUE(this); |
| 743 | return NAN_OR_SEC_FROM_TIME(t); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 744 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 745 | |
| 746 | |
| 747 | // ECMA 262 - 15.9.5.24 |
| 748 | function DateGetMilliseconds() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 749 | var t = DATE_VALUE(this); |
| 750 | if (NUMBER_IS_NAN(t)) return t; |
| 751 | return MS_FROM_TIME(LocalTimeNoCheck(t)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 752 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 753 | |
| 754 | |
| 755 | // ECMA 262 - 15.9.5.25 |
| 756 | function DateGetUTCMilliseconds() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 757 | var t = DATE_VALUE(this); |
| 758 | return NAN_OR_MS_FROM_TIME(t); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 759 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 760 | |
| 761 | |
| 762 | // ECMA 262 - 15.9.5.26 |
| 763 | function DateGetTimezoneOffset() { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 764 | var t = DATE_VALUE(this); |
| 765 | if (NUMBER_IS_NAN(t)) return t; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 766 | return (t - LocalTimeNoCheck(t)) / msPerMinute; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 767 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 768 | |
| 769 | |
| 770 | // ECMA 262 - 15.9.5.27 |
| 771 | function DateSetTime(ms) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 772 | if (!IS_DATE(this)) ThrowDateTypeError(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 773 | return %_SetValueOf(this, TimeClip(ToNumber(ms))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 774 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 775 | |
| 776 | |
| 777 | // ECMA 262 - 15.9.5.28 |
| 778 | function DateSetMilliseconds(ms) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 779 | var t = LocalTime(DATE_VALUE(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 780 | ms = ToNumber(ms); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 781 | var time = MakeTime(HOUR_FROM_TIME(t), MIN_FROM_TIME(t), SEC_FROM_TIME(t), ms); |
| 782 | return %_SetValueOf(this, TimeClip(UTC(MakeDate(DAY(t), time)))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 783 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 784 | |
| 785 | |
| 786 | // ECMA 262 - 15.9.5.29 |
| 787 | function DateSetUTCMilliseconds(ms) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 788 | var t = DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 789 | ms = ToNumber(ms); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 790 | var time = MakeTime(HOUR_FROM_TIME(t), MIN_FROM_TIME(t), SEC_FROM_TIME(t), ms); |
| 791 | return %_SetValueOf(this, TimeClip(MakeDate(DAY(t), time))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 792 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 793 | |
| 794 | |
| 795 | // ECMA 262 - 15.9.5.30 |
| 796 | function DateSetSeconds(sec, ms) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 797 | var t = LocalTime(DATE_VALUE(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 798 | sec = ToNumber(sec); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 799 | ms = %_ArgumentsLength() < 2 ? NAN_OR_MS_FROM_TIME(t) : ToNumber(ms); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 800 | var time = MakeTime(HOUR_FROM_TIME(t), MIN_FROM_TIME(t), sec, ms); |
| 801 | return %_SetValueOf(this, TimeClip(UTC(MakeDate(DAY(t), time)))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 802 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 803 | |
| 804 | |
| 805 | // ECMA 262 - 15.9.5.31 |
| 806 | function DateSetUTCSeconds(sec, ms) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 807 | var t = DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 808 | sec = ToNumber(sec); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 809 | ms = %_ArgumentsLength() < 2 ? NAN_OR_MS_FROM_TIME(t) : ToNumber(ms); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 810 | var time = MakeTime(HOUR_FROM_TIME(t), MIN_FROM_TIME(t), sec, ms); |
| 811 | return %_SetValueOf(this, TimeClip(MakeDate(DAY(t), time))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 812 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 813 | |
| 814 | |
| 815 | // ECMA 262 - 15.9.5.33 |
| 816 | function DateSetMinutes(min, sec, ms) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 817 | var t = LocalTime(DATE_VALUE(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 818 | min = ToNumber(min); |
| 819 | var argc = %_ArgumentsLength(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 820 | sec = argc < 2 ? NAN_OR_SEC_FROM_TIME(t) : ToNumber(sec); |
| 821 | ms = argc < 3 ? NAN_OR_MS_FROM_TIME(t) : ToNumber(ms); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 822 | var time = MakeTime(HOUR_FROM_TIME(t), min, sec, ms); |
| 823 | return %_SetValueOf(this, TimeClip(UTC(MakeDate(DAY(t), time)))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 824 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 825 | |
| 826 | |
| 827 | // ECMA 262 - 15.9.5.34 |
| 828 | function DateSetUTCMinutes(min, sec, ms) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 829 | var t = DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 830 | min = ToNumber(min); |
| 831 | var argc = %_ArgumentsLength(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 832 | sec = argc < 2 ? NAN_OR_SEC_FROM_TIME(t) : ToNumber(sec); |
| 833 | ms = argc < 3 ? NAN_OR_MS_FROM_TIME(t) : ToNumber(ms); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 834 | var time = MakeTime(HOUR_FROM_TIME(t), min, sec, ms); |
| 835 | return %_SetValueOf(this, TimeClip(MakeDate(DAY(t), time))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 836 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 837 | |
| 838 | |
| 839 | // ECMA 262 - 15.9.5.35 |
| 840 | function DateSetHours(hour, min, sec, ms) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 841 | var t = LocalTime(DATE_VALUE(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 842 | hour = ToNumber(hour); |
| 843 | var argc = %_ArgumentsLength(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 844 | min = argc < 2 ? NAN_OR_MIN_FROM_TIME(t) : ToNumber(min); |
| 845 | sec = argc < 3 ? NAN_OR_SEC_FROM_TIME(t) : ToNumber(sec); |
| 846 | ms = argc < 4 ? NAN_OR_MS_FROM_TIME(t) : ToNumber(ms); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 847 | var time = MakeTime(hour, min, sec, ms); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 848 | return %_SetValueOf(this, TimeClip(UTC(MakeDate(DAY(t), time)))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 849 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 850 | |
| 851 | |
| 852 | // ECMA 262 - 15.9.5.34 |
| 853 | function DateSetUTCHours(hour, min, sec, ms) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 854 | var t = DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 855 | hour = ToNumber(hour); |
| 856 | var argc = %_ArgumentsLength(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 857 | min = argc < 2 ? NAN_OR_MIN_FROM_TIME(t) : ToNumber(min); |
| 858 | sec = argc < 3 ? NAN_OR_SEC_FROM_TIME(t) : ToNumber(sec); |
| 859 | ms = argc < 4 ? NAN_OR_MS_FROM_TIME(t) : ToNumber(ms); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 860 | var time = MakeTime(hour, min, sec, ms); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 861 | return %_SetValueOf(this, TimeClip(MakeDate(DAY(t), time))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 862 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 863 | |
| 864 | |
| 865 | // ECMA 262 - 15.9.5.36 |
| 866 | function DateSetDate(date) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 867 | var t = LocalTime(DATE_VALUE(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 868 | date = ToNumber(date); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 869 | var day = MakeDay(YearFromTime(t), MonthFromTime(t), date); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 870 | return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 871 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 872 | |
| 873 | |
| 874 | // ECMA 262 - 15.9.5.37 |
| 875 | function DateSetUTCDate(date) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 876 | var t = DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 877 | date = ToNumber(date); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 878 | var day = MakeDay(YearFromTime(t), MonthFromTime(t), date); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 879 | return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 880 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 881 | |
| 882 | |
| 883 | // ECMA 262 - 15.9.5.38 |
| 884 | function DateSetMonth(month, date) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 885 | var t = LocalTime(DATE_VALUE(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 886 | month = ToNumber(month); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 887 | date = %_ArgumentsLength() < 2 ? NAN_OR_DATE_FROM_TIME(t) : ToNumber(date); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 888 | var day = MakeDay(YearFromTime(t), month, date); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 889 | return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 890 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 891 | |
| 892 | |
| 893 | // ECMA 262 - 15.9.5.39 |
| 894 | function DateSetUTCMonth(month, date) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 895 | var t = DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 896 | month = ToNumber(month); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 897 | date = %_ArgumentsLength() < 2 ? NAN_OR_DATE_FROM_TIME(t) : ToNumber(date); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 898 | var day = MakeDay(YearFromTime(t), month, date); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 899 | return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 900 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 901 | |
| 902 | |
| 903 | // ECMA 262 - 15.9.5.40 |
| 904 | function DateSetFullYear(year, month, date) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 905 | var t = DATE_VALUE(this); |
| 906 | t = NUMBER_IS_NAN(t) ? 0 : LocalTimeNoCheck(t); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 907 | year = ToNumber(year); |
| 908 | var argc = %_ArgumentsLength(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 909 | month = argc < 2 ? MonthFromTime(t) : ToNumber(month); |
| 910 | date = argc < 3 ? DateFromTime(t) : ToNumber(date); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 911 | var day = MakeDay(year, month, date); |
| 912 | return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 913 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 914 | |
| 915 | |
| 916 | // ECMA 262 - 15.9.5.41 |
| 917 | function DateSetUTCFullYear(year, month, date) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 918 | var t = DATE_VALUE(this); |
| 919 | if (NUMBER_IS_NAN(t)) t = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 920 | var argc = %_ArgumentsLength(); |
| 921 | year = ToNumber(year); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 922 | month = argc < 2 ? MonthFromTime(t) : ToNumber(month); |
| 923 | date = argc < 3 ? DateFromTime(t) : ToNumber(date); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 924 | var day = MakeDay(year, month, date); |
| 925 | return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t)))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 926 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 927 | |
| 928 | |
| 929 | // ECMA 262 - 15.9.5.42 |
| 930 | function DateToUTCString() { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 931 | var t = DATE_VALUE(this); |
| 932 | if (NUMBER_IS_NAN(t)) return kInvalidDate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 933 | // Return UTC string of the form: Sat, 31 Jan 1970 23:00:00 GMT |
| 934 | return WeekDays[WeekDay(t)] + ', ' |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 935 | + TwoDigitString(DateFromTime(t)) + ' ' |
| 936 | + Months[MonthFromTime(t)] + ' ' |
| 937 | + YearFromTime(t) + ' ' |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 938 | + TimeString(t) + ' GMT'; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 939 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 940 | |
| 941 | |
| 942 | // ECMA 262 - B.2.4 |
| 943 | function DateGetYear() { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 944 | var t = DATE_VALUE(this); |
| 945 | if (NUMBER_IS_NAN(t)) return $NaN; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 946 | return YearFromTime(LocalTimeNoCheck(t)) - 1900; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 947 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 948 | |
| 949 | |
| 950 | // ECMA 262 - B.2.5 |
| 951 | function DateSetYear(year) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 952 | var t = LocalTime(DATE_VALUE(this)); |
| 953 | if (NUMBER_IS_NAN(t)) t = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 954 | year = ToNumber(year); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 955 | if (NUMBER_IS_NAN(year)) return %_SetValueOf(this, $NaN); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 956 | year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) |
| 957 | ? 1900 + TO_INTEGER(year) : year; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 958 | var day = MakeDay(year, MonthFromTime(t), DateFromTime(t)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 959 | return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t))))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | |
| 963 | // ECMA 262 - B.2.6 |
| 964 | // |
| 965 | // Notice that this does not follow ECMA 262 completely. ECMA 262 |
| 966 | // says that toGMTString should be the same Function object as |
| 967 | // toUTCString. JSC does not do this, so for compatibility we do not |
| 968 | // do that either. Instead, we create a new function whose name |
| 969 | // property will return toGMTString. |
| 970 | function DateToGMTString() { |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 971 | return %_CallFunction(this, DateToUTCString); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 972 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 973 | |
| 974 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 975 | function PadInt(n, digits) { |
| 976 | if (digits == 1) return n; |
| 977 | return n < MathPow(10, digits - 1) ? '0' + PadInt(n, digits - 1) : n; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | |
| 981 | function DateToISOString() { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 982 | var t = DATE_VALUE(this); |
| 983 | if (NUMBER_IS_NAN(t)) return kInvalidDate; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 984 | var year = this.getUTCFullYear(); |
| 985 | var year_string; |
| 986 | if (year >= 0 && year <= 9999) { |
| 987 | year_string = PadInt(year, 4); |
| 988 | } else { |
| 989 | if (year < 0) { |
| 990 | year_string = "-" + PadInt(-year, 6); |
| 991 | } else { |
| 992 | year_string = "+" + PadInt(year, 6); |
| 993 | } |
| 994 | } |
| 995 | return year_string + |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 996 | '-' + PadInt(this.getUTCMonth() + 1, 2) + |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 997 | '-' + PadInt(this.getUTCDate(), 2) + |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 998 | 'T' + PadInt(this.getUTCHours(), 2) + |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 999 | ':' + PadInt(this.getUTCMinutes(), 2) + |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1000 | ':' + PadInt(this.getUTCSeconds(), 2) + |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1001 | '.' + PadInt(this.getUTCMilliseconds(), 3) + |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 1002 | 'Z'; |
| 1003 | } |
| 1004 | |
| 1005 | |
| 1006 | function DateToJSON(key) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1007 | var o = ToObject(this); |
| 1008 | var tv = DefaultNumber(o); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1009 | if (IS_NUMBER(tv) && !NUMBER_IS_FINITE(tv)) { |
| 1010 | return null; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1011 | } |
| 1012 | return o.toISOString(); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1016 | function ResetDateCache() { |
| 1017 | |
| 1018 | // Reset the local_time_offset: |
| 1019 | local_time_offset = %DateLocalTimeOffset(); |
| 1020 | |
| 1021 | // Reset the DST offset cache: |
| 1022 | var cache = DST_offset_cache; |
| 1023 | cache.offset = 0; |
| 1024 | cache.start = 0; |
| 1025 | cache.end = -1; |
| 1026 | cache.increment = 0; |
| 1027 | cache.initial_increment = 19 * msPerDay; |
| 1028 | |
| 1029 | // Reset the timezone cache: |
| 1030 | timezone_cache_time = $NaN; |
| 1031 | timezone_cache_timezone = undefined; |
| 1032 | |
| 1033 | // Reset the ltcache: |
| 1034 | ltcache.key = null; |
| 1035 | ltcache.val = null; |
| 1036 | |
| 1037 | // Reset the ymd_from_time_cache: |
| 1038 | ymd_from_time_cache = [$NaN, $NaN, $NaN]; |
| 1039 | ymd_from_time_cached_time = $NaN; |
| 1040 | |
| 1041 | // Reset the date cache: |
| 1042 | cache = Date_cache; |
| 1043 | cache.time = $NaN; |
| 1044 | cache.year = $NaN; |
| 1045 | cache.string = null; |
| 1046 | } |
| 1047 | |
| 1048 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1049 | // ------------------------------------------------------------------- |
| 1050 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1051 | function SetUpDate() { |
| 1052 | %CheckIsBootstrapping(); |
| 1053 | // Set up non-enumerable properties of the Date object itself. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1054 | InstallFunctions($Date, DONT_ENUM, $Array( |
| 1055 | "UTC", DateUTC, |
| 1056 | "parse", DateParse, |
| 1057 | "now", DateNow |
| 1058 | )); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1059 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1060 | // Set up non-enumerable constructor property of the Date prototype object. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1061 | %SetProperty($Date.prototype, "constructor", $Date, DONT_ENUM); |
| 1062 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1063 | // Set up non-enumerable functions of the Date prototype object and |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1064 | // set their names. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1065 | InstallFunctionsOnHiddenPrototype($Date.prototype, DONT_ENUM, $Array( |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1066 | "toString", DateToString, |
| 1067 | "toDateString", DateToDateString, |
| 1068 | "toTimeString", DateToTimeString, |
| 1069 | "toLocaleString", DateToLocaleString, |
| 1070 | "toLocaleDateString", DateToLocaleDateString, |
| 1071 | "toLocaleTimeString", DateToLocaleTimeString, |
| 1072 | "valueOf", DateValueOf, |
| 1073 | "getTime", DateGetTime, |
| 1074 | "getFullYear", DateGetFullYear, |
| 1075 | "getUTCFullYear", DateGetUTCFullYear, |
| 1076 | "getMonth", DateGetMonth, |
| 1077 | "getUTCMonth", DateGetUTCMonth, |
| 1078 | "getDate", DateGetDate, |
| 1079 | "getUTCDate", DateGetUTCDate, |
| 1080 | "getDay", DateGetDay, |
| 1081 | "getUTCDay", DateGetUTCDay, |
| 1082 | "getHours", DateGetHours, |
| 1083 | "getUTCHours", DateGetUTCHours, |
| 1084 | "getMinutes", DateGetMinutes, |
| 1085 | "getUTCMinutes", DateGetUTCMinutes, |
| 1086 | "getSeconds", DateGetSeconds, |
| 1087 | "getUTCSeconds", DateGetUTCSeconds, |
| 1088 | "getMilliseconds", DateGetMilliseconds, |
| 1089 | "getUTCMilliseconds", DateGetUTCMilliseconds, |
| 1090 | "getTimezoneOffset", DateGetTimezoneOffset, |
| 1091 | "setTime", DateSetTime, |
| 1092 | "setMilliseconds", DateSetMilliseconds, |
| 1093 | "setUTCMilliseconds", DateSetUTCMilliseconds, |
| 1094 | "setSeconds", DateSetSeconds, |
| 1095 | "setUTCSeconds", DateSetUTCSeconds, |
| 1096 | "setMinutes", DateSetMinutes, |
| 1097 | "setUTCMinutes", DateSetUTCMinutes, |
| 1098 | "setHours", DateSetHours, |
| 1099 | "setUTCHours", DateSetUTCHours, |
| 1100 | "setDate", DateSetDate, |
| 1101 | "setUTCDate", DateSetUTCDate, |
| 1102 | "setMonth", DateSetMonth, |
| 1103 | "setUTCMonth", DateSetUTCMonth, |
| 1104 | "setFullYear", DateSetFullYear, |
| 1105 | "setUTCFullYear", DateSetUTCFullYear, |
| 1106 | "toGMTString", DateToGMTString, |
| 1107 | "toUTCString", DateToUTCString, |
| 1108 | "getYear", DateGetYear, |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 1109 | "setYear", DateSetYear, |
| 1110 | "toISOString", DateToISOString, |
| 1111 | "toJSON", DateToJSON |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1112 | )); |
| 1113 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1114 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1115 | SetUpDate(); |