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: |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 31 | // var $isFinite = GlobalIsFinite; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 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 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | // Keep reference to original values of some global properties. This |
| 38 | // has the added benefit that the code in this file is isolated from |
| 39 | // changes to these properties. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 40 | var $Date = global.Date; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 42 | // Helper function to throw error. |
| 43 | function ThrowDateTypeError() { |
| 44 | throw new $TypeError('this is not a Date object.'); |
| 45 | } |
| 46 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | |
| 48 | var timezone_cache_time = $NaN; |
| 49 | var timezone_cache_timezone; |
| 50 | |
| 51 | function LocalTimezone(t) { |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 52 | if (NUMBER_IS_NAN(t)) return ""; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 53 | if (t == timezone_cache_time) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 54 | return timezone_cache_timezone; |
| 55 | } |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 56 | var timezone = %DateLocalTimezone(t); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 57 | timezone_cache_time = t; |
| 58 | timezone_cache_timezone = timezone; |
| 59 | return timezone; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 60 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 61 | |
| 62 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 63 | function UTC(time) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 64 | if (NUMBER_IS_NAN(time)) return time; |
whesse@chromium.org | 421a0f4 | 2010-03-30 15:09:23 +0000 | [diff] [blame] | 65 | // local_time_offset is needed before the call to DaylightSavingsOffset, |
| 66 | // so it may be uninitialized. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 67 | return %DateToUTC(time); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 68 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 69 | |
| 70 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 71 | // ECMA 262 - 15.9.1.11 |
| 72 | function MakeTime(hour, min, sec, ms) { |
| 73 | if (!$isFinite(hour)) return $NaN; |
| 74 | if (!$isFinite(min)) return $NaN; |
| 75 | if (!$isFinite(sec)) return $NaN; |
| 76 | if (!$isFinite(ms)) return $NaN; |
| 77 | return TO_INTEGER(hour) * msPerHour |
| 78 | + TO_INTEGER(min) * msPerMinute |
| 79 | + TO_INTEGER(sec) * msPerSecond |
| 80 | + TO_INTEGER(ms); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 81 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 82 | |
| 83 | |
| 84 | // ECMA 262 - 15.9.1.12 |
| 85 | function TimeInYear(year) { |
| 86 | return DaysInYear(year) * msPerDay; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 87 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 88 | |
| 89 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 90 | // Compute number of days given a year, month, date. |
| 91 | // Note that month and date can lie outside the normal range. |
| 92 | // For example: |
| 93 | // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20) |
| 94 | // MakeDay(2007, -33, 1) --> MakeDay(2004, 3, 1) |
| 95 | // MakeDay(2007, 14, -50) --> MakeDay(2007, 8, 11) |
| 96 | function MakeDay(year, month, date) { |
| 97 | if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) return $NaN; |
| 98 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 99 | // Convert to integer and map -0 to 0. |
| 100 | year = TO_INTEGER_MAP_MINUS_ZERO(year); |
| 101 | month = TO_INTEGER_MAP_MINUS_ZERO(month); |
| 102 | date = TO_INTEGER_MAP_MINUS_ZERO(date); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 104 | if (year < kMinYear || year > kMaxYear || |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 105 | month < kMinMonth || month > kMaxMonth) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 106 | return $NaN; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 107 | } |
| 108 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 109 | // Now we rely on year and month being SMIs. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 110 | return %DateMakeDay(year | 0, month | 0) + date - 1; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 111 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 112 | |
| 113 | |
| 114 | // ECMA 262 - 15.9.1.13 |
| 115 | function MakeDate(day, time) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 116 | var time = day * msPerDay + time; |
| 117 | // Some of our runtime funtions for computing UTC(time) rely on |
| 118 | // times not being significantly larger than MAX_TIME_MS. If there |
| 119 | // is no way that the time can be within range even after UTC |
| 120 | // conversion we return NaN immediately instead of relying on |
| 121 | // TimeClip to do it. |
| 122 | if ($abs(time) > MAX_TIME_BEFORE_UTC) return $NaN; |
| 123 | return time; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 124 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 125 | |
| 126 | |
| 127 | // ECMA 262 - 15.9.1.14 |
| 128 | function TimeClip(time) { |
| 129 | if (!$isFinite(time)) return $NaN; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 130 | if ($abs(time) > MAX_TIME_MS) return $NaN; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 131 | return TO_INTEGER(time); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 132 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 133 | |
| 134 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 135 | // The Date cache is used to limit the cost of parsing the same Date |
| 136 | // strings over and over again. |
| 137 | var Date_cache = { |
| 138 | // Cached time value. |
| 139 | time: $NaN, |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 140 | // String input for which the cached time is valid. |
| 141 | string: null |
| 142 | }; |
| 143 | |
| 144 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 145 | %SetCode($Date, function(year, month, date, hours, minutes, seconds, ms) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 146 | if (!%_IsConstructCall()) { |
| 147 | // ECMA 262 - 15.9.2 |
| 148 | return (new $Date()).toString(); |
| 149 | } |
| 150 | |
| 151 | // ECMA 262 - 15.9.3 |
| 152 | var argc = %_ArgumentsLength(); |
| 153 | var value; |
| 154 | if (argc == 0) { |
| 155 | value = %DateCurrentTime(); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 156 | SET_UTC_DATE_VALUE(this, value); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 157 | } else if (argc == 1) { |
| 158 | if (IS_NUMBER(year)) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 159 | value = year; |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 160 | } else if (IS_STRING(year)) { |
| 161 | // Probe the Date cache. If we already have a time value for the |
| 162 | // given time, we re-use that instead of parsing the string again. |
| 163 | var cache = Date_cache; |
| 164 | if (cache.string === year) { |
| 165 | value = cache.time; |
| 166 | } else { |
| 167 | value = DateParse(year); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 168 | if (!NUMBER_IS_NAN(value)) { |
| 169 | cache.time = value; |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 170 | cache.string = year; |
| 171 | } |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 172 | } |
| 173 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 174 | } else { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 175 | // According to ECMA 262, no hint should be given for this |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 176 | // conversion. However, ToPrimitive defaults to STRING_HINT for |
| 177 | // Date objects which will lose precision when the Date |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 178 | // constructor is called with another Date object as its |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 179 | // argument. We therefore use NUMBER_HINT for the conversion, |
| 180 | // which is the default for everything else than Date objects. |
| 181 | // This makes us behave like KJS and SpiderMonkey. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 182 | var time = ToPrimitive(year, NUMBER_HINT); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 183 | value = IS_STRING(time) ? DateParse(time) : ToNumber(time); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 184 | } |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 185 | SET_UTC_DATE_VALUE(this, value); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 186 | } else { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 187 | year = ToNumber(year); |
| 188 | month = ToNumber(month); |
| 189 | date = argc > 2 ? ToNumber(date) : 1; |
| 190 | hours = argc > 3 ? ToNumber(hours) : 0; |
| 191 | minutes = argc > 4 ? ToNumber(minutes) : 0; |
| 192 | seconds = argc > 5 ? ToNumber(seconds) : 0; |
| 193 | ms = argc > 6 ? ToNumber(ms) : 0; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 194 | year = (!NUMBER_IS_NAN(year) && |
| 195 | 0 <= TO_INTEGER(year) && |
| 196 | TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 197 | var day = MakeDay(year, month, date); |
| 198 | var time = MakeTime(hours, minutes, seconds, ms); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 199 | value = MakeDate(day, time); |
| 200 | SET_LOCAL_DATE_VALUE(this, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 201 | } |
| 202 | }); |
| 203 | |
| 204 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 205 | %FunctionSetPrototype($Date, new $Date($NaN)); |
| 206 | |
| 207 | |
| 208 | var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 209 | var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', |
| 210 | 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 211 | |
| 212 | |
| 213 | function TwoDigitString(value) { |
| 214 | return value < 10 ? "0" + value : "" + value; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 215 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 216 | |
| 217 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 218 | function DateString(date) { |
| 219 | return WeekDays[LOCAL_WEEKDAY(date)] + ' ' |
| 220 | + Months[LOCAL_MONTH(date)] + ' ' |
| 221 | + TwoDigitString(LOCAL_DAY(date)) + ' ' |
| 222 | + LOCAL_YEAR(date); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 223 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 224 | |
| 225 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 226 | var LongWeekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', |
| 227 | 'Thursday', 'Friday', 'Saturday']; |
| 228 | var LongMonths = ['January', 'February', 'March', 'April', 'May', 'June', |
| 229 | 'July', 'August', 'September', 'October', 'November', 'December']; |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 230 | |
| 231 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 232 | function LongDateString(date) { |
| 233 | return LongWeekDays[LOCAL_WEEKDAY(date)] + ', ' |
| 234 | + LongMonths[LOCAL_MONTH(date)] + ' ' |
| 235 | + TwoDigitString(LOCAL_DAY(date)) + ', ' |
| 236 | + LOCAL_YEAR(date); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 240 | function TimeString(date) { |
| 241 | return TwoDigitString(LOCAL_HOUR(date)) + ':' |
| 242 | + TwoDigitString(LOCAL_MIN(date)) + ':' |
| 243 | + TwoDigitString(LOCAL_SEC(date)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 244 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 245 | |
| 246 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 247 | function TimeStringUTC(date) { |
| 248 | return TwoDigitString(UTC_HOUR(date)) + ':' |
| 249 | + TwoDigitString(UTC_MIN(date)) + ':' |
| 250 | + TwoDigitString(UTC_SEC(date)); |
| 251 | } |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 252 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 253 | |
| 254 | function LocalTimezoneString(date) { |
| 255 | var timezone = LocalTimezone(UTC_DATE_VALUE(date)); |
| 256 | |
| 257 | var timezoneOffset = -TIMEZONE_OFFSET(date); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 258 | var sign = (timezoneOffset >= 0) ? 1 : -1; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 259 | var hours = FLOOR((sign * timezoneOffset)/60); |
| 260 | var min = FLOOR((sign * timezoneOffset)%60); |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 261 | var gmt = ' GMT' + ((sign == 1) ? '+' : '-') + |
| 262 | TwoDigitString(hours) + TwoDigitString(min); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 263 | return gmt + ' (' + timezone + ')'; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 264 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 265 | |
| 266 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 267 | function DatePrintString(date) { |
| 268 | return DateString(date) + ' ' + TimeString(date); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 269 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 270 | |
| 271 | // ------------------------------------------------------------------- |
| 272 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 273 | // Reused output buffer. Used when parsing date strings. |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 274 | var parse_buffer = $Array(8); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 275 | |
| 276 | // ECMA 262 - 15.9.4.2 |
| 277 | function DateParse(string) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 278 | var arr = %DateParseString(ToString(string), parse_buffer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 279 | if (IS_NULL(arr)) return $NaN; |
| 280 | |
| 281 | var day = MakeDay(arr[0], arr[1], arr[2]); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 282 | var time = MakeTime(arr[3], arr[4], arr[5], arr[6]); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 283 | var date = MakeDate(day, time); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 284 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 285 | if (IS_NULL(arr[7])) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 286 | return TimeClip(UTC(date)); |
| 287 | } else { |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 288 | return TimeClip(date - arr[7] * 1000); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 289 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 290 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 291 | |
| 292 | |
| 293 | // ECMA 262 - 15.9.4.3 |
| 294 | function DateUTC(year, month, date, hours, minutes, seconds, ms) { |
| 295 | year = ToNumber(year); |
| 296 | month = ToNumber(month); |
| 297 | var argc = %_ArgumentsLength(); |
| 298 | date = argc > 2 ? ToNumber(date) : 1; |
| 299 | hours = argc > 3 ? ToNumber(hours) : 0; |
| 300 | minutes = argc > 4 ? ToNumber(minutes) : 0; |
| 301 | seconds = argc > 5 ? ToNumber(seconds) : 0; |
| 302 | ms = argc > 6 ? ToNumber(ms) : 0; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 303 | year = (!NUMBER_IS_NAN(year) && |
| 304 | 0 <= TO_INTEGER(year) && |
| 305 | TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 306 | var day = MakeDay(year, month, date); |
| 307 | var time = MakeTime(hours, minutes, seconds, ms); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 308 | return TimeClip(MakeDate(day, time)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 309 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 310 | |
| 311 | |
| 312 | // Mozilla-specific extension. Returns the number of milliseconds |
| 313 | // elapsed since 1 January 1970 00:00:00 UTC. |
| 314 | function DateNow() { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 315 | return %DateCurrentTime(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 316 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 317 | |
| 318 | |
| 319 | // ECMA 262 - 15.9.5.2 |
| 320 | function DateToString() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 321 | var t = UTC_DATE_VALUE(this) |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 322 | if (NUMBER_IS_NAN(t)) return kInvalidDate; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 323 | var time_zone_string = LocalTimezoneString(this) |
| 324 | return DatePrintString(this) + time_zone_string; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 325 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 326 | |
| 327 | |
| 328 | // ECMA 262 - 15.9.5.3 |
| 329 | function DateToDateString() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 330 | var t = UTC_DATE_VALUE(this); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 331 | if (NUMBER_IS_NAN(t)) return kInvalidDate; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 332 | return DateString(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 333 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 334 | |
| 335 | |
| 336 | // ECMA 262 - 15.9.5.4 |
| 337 | function DateToTimeString() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 338 | var t = UTC_DATE_VALUE(this); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 339 | if (NUMBER_IS_NAN(t)) return kInvalidDate; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 340 | var time_zone_string = LocalTimezoneString(this); |
| 341 | return TimeString(this) + time_zone_string; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | |
| 345 | // ECMA 262 - 15.9.5.5 |
| 346 | function DateToLocaleString() { |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 347 | return %_CallFunction(this, DateToString); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | |
| 351 | // ECMA 262 - 15.9.5.6 |
| 352 | function DateToLocaleDateString() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 353 | var t = UTC_DATE_VALUE(this); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 354 | if (NUMBER_IS_NAN(t)) return kInvalidDate; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 355 | return LongDateString(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 356 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 357 | |
| 358 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 359 | // ECMA 262 - 15.9.5.7 |
| 360 | function DateToLocaleTimeString() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 361 | var t = UTC_DATE_VALUE(this); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 362 | if (NUMBER_IS_NAN(t)) return kInvalidDate; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 363 | return TimeString(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | |
| 367 | // ECMA 262 - 15.9.5.8 |
| 368 | function DateValueOf() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 369 | return UTC_DATE_VALUE(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 370 | } |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 371 | |
| 372 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 373 | // ECMA 262 - 15.9.5.9 |
| 374 | function DateGetTime() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 375 | return UTC_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | |
| 379 | // ECMA 262 - 15.9.5.10 |
| 380 | function DateGetFullYear() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 381 | return LOCAL_YEAR(this); |
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 | |
| 385 | // ECMA 262 - 15.9.5.11 |
| 386 | function DateGetUTCFullYear() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 387 | return UTC_YEAR(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 388 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 389 | |
| 390 | |
| 391 | // ECMA 262 - 15.9.5.12 |
| 392 | function DateGetMonth() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 393 | return LOCAL_MONTH(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 394 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 395 | |
| 396 | |
| 397 | // ECMA 262 - 15.9.5.13 |
| 398 | function DateGetUTCMonth() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 399 | return UTC_MONTH(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 400 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 401 | |
| 402 | |
| 403 | // ECMA 262 - 15.9.5.14 |
| 404 | function DateGetDate() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 405 | return LOCAL_DAY(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 406 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 407 | |
| 408 | |
| 409 | // ECMA 262 - 15.9.5.15 |
| 410 | function DateGetUTCDate() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 411 | return UTC_DAY(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 412 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 413 | |
| 414 | |
| 415 | // ECMA 262 - 15.9.5.16 |
| 416 | function DateGetDay() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 417 | return LOCAL_WEEKDAY(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 418 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 419 | |
| 420 | |
| 421 | // ECMA 262 - 15.9.5.17 |
| 422 | function DateGetUTCDay() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 423 | return UTC_WEEKDAY(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 424 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 425 | |
| 426 | |
| 427 | // ECMA 262 - 15.9.5.18 |
| 428 | function DateGetHours() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 429 | return LOCAL_HOUR(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 430 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 431 | |
| 432 | |
| 433 | // ECMA 262 - 15.9.5.19 |
| 434 | function DateGetUTCHours() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 435 | return UTC_HOUR(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 436 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 437 | |
| 438 | |
| 439 | // ECMA 262 - 15.9.5.20 |
| 440 | function DateGetMinutes() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 441 | return LOCAL_MIN(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 442 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 443 | |
| 444 | |
| 445 | // ECMA 262 - 15.9.5.21 |
| 446 | function DateGetUTCMinutes() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 447 | return UTC_MIN(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 448 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 449 | |
| 450 | |
| 451 | // ECMA 262 - 15.9.5.22 |
| 452 | function DateGetSeconds() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 453 | return LOCAL_SEC(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 454 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 455 | |
| 456 | |
| 457 | // ECMA 262 - 15.9.5.23 |
| 458 | function DateGetUTCSeconds() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 459 | return UTC_SEC(this) |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 460 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 461 | |
| 462 | |
| 463 | // ECMA 262 - 15.9.5.24 |
| 464 | function DateGetMilliseconds() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 465 | return LOCAL_MS(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 466 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 467 | |
| 468 | |
| 469 | // ECMA 262 - 15.9.5.25 |
| 470 | function DateGetUTCMilliseconds() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 471 | return UTC_MS(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 472 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 473 | |
| 474 | |
| 475 | // ECMA 262 - 15.9.5.26 |
| 476 | function DateGetTimezoneOffset() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 477 | return TIMEZONE_OFFSET(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 478 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 479 | |
| 480 | |
| 481 | // ECMA 262 - 15.9.5.27 |
| 482 | function DateSetTime(ms) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 483 | CHECK_DATE(this); |
| 484 | SET_UTC_DATE_VALUE(this, ToNumber(ms)); |
| 485 | return UTC_DATE_VALUE(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 486 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 487 | |
| 488 | |
| 489 | // ECMA 262 - 15.9.5.28 |
| 490 | function DateSetMilliseconds(ms) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 491 | var t = LOCAL_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 492 | ms = ToNumber(ms); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 493 | var time = MakeTime(LOCAL_HOUR(this), LOCAL_MIN(this), LOCAL_SEC(this), ms); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 494 | return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), 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 | // ECMA 262 - 15.9.5.29 |
| 499 | function DateSetUTCMilliseconds(ms) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 500 | var t = UTC_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 501 | ms = ToNumber(ms); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 502 | var time = MakeTime(UTC_HOUR(this), |
| 503 | UTC_MIN(this), |
| 504 | UTC_SEC(this), |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 505 | ms); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 506 | return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 507 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 508 | |
| 509 | |
| 510 | // ECMA 262 - 15.9.5.30 |
| 511 | function DateSetSeconds(sec, ms) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 512 | var t = LOCAL_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 513 | sec = ToNumber(sec); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 514 | ms = %_ArgumentsLength() < 2 ? LOCAL_MS(this) : ToNumber(ms); |
| 515 | var time = MakeTime(LOCAL_HOUR(this), LOCAL_MIN(this), sec, ms); |
| 516 | return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 517 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 518 | |
| 519 | |
| 520 | // ECMA 262 - 15.9.5.31 |
| 521 | function DateSetUTCSeconds(sec, ms) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 522 | var t = UTC_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 523 | sec = ToNumber(sec); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 524 | ms = %_ArgumentsLength() < 2 ? UTC_MS(this) : ToNumber(ms); |
| 525 | var time = MakeTime(UTC_HOUR(this), UTC_MIN(this), sec, ms); |
| 526 | return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 527 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 528 | |
| 529 | |
| 530 | // ECMA 262 - 15.9.5.33 |
| 531 | function DateSetMinutes(min, sec, ms) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 532 | var t = LOCAL_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | min = ToNumber(min); |
| 534 | var argc = %_ArgumentsLength(); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 535 | sec = argc < 2 ? LOCAL_SEC(this) : ToNumber(sec); |
| 536 | ms = argc < 3 ? LOCAL_MS(this) : ToNumber(ms); |
| 537 | var time = MakeTime(LOCAL_HOUR(this), min, sec, ms); |
| 538 | return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 539 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 540 | |
| 541 | |
| 542 | // ECMA 262 - 15.9.5.34 |
| 543 | function DateSetUTCMinutes(min, sec, ms) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 544 | var t = UTC_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | min = ToNumber(min); |
| 546 | var argc = %_ArgumentsLength(); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 547 | sec = argc < 2 ? UTC_SEC(this) : ToNumber(sec); |
| 548 | ms = argc < 3 ? UTC_MS(this) : ToNumber(ms); |
| 549 | var time = MakeTime(UTC_HOUR(this), min, sec, ms); |
| 550 | return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 551 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 552 | |
| 553 | |
| 554 | // ECMA 262 - 15.9.5.35 |
| 555 | function DateSetHours(hour, min, sec, ms) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 556 | var t = LOCAL_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | hour = ToNumber(hour); |
| 558 | var argc = %_ArgumentsLength(); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 559 | min = argc < 2 ? LOCAL_MIN(this) : ToNumber(min); |
| 560 | sec = argc < 3 ? LOCAL_SEC(this) : ToNumber(sec); |
| 561 | ms = argc < 4 ? LOCAL_MS(this) : ToNumber(ms); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 562 | var time = MakeTime(hour, min, sec, ms); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 563 | return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 564 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 565 | |
| 566 | |
| 567 | // ECMA 262 - 15.9.5.34 |
| 568 | function DateSetUTCHours(hour, min, sec, ms) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 569 | var t = UTC_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 570 | hour = ToNumber(hour); |
| 571 | var argc = %_ArgumentsLength(); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 572 | min = argc < 2 ? UTC_MIN(this) : ToNumber(min); |
| 573 | sec = argc < 3 ? UTC_SEC(this) : ToNumber(sec); |
| 574 | ms = argc < 4 ? UTC_MS(this) : ToNumber(ms); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 575 | var time = MakeTime(hour, min, sec, ms); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 576 | return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 577 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 578 | |
| 579 | |
| 580 | // ECMA 262 - 15.9.5.36 |
| 581 | function DateSetDate(date) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 582 | var t = LOCAL_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 583 | date = ToNumber(date); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 584 | var day = MakeDay(LOCAL_YEAR(this), LOCAL_MONTH(this), date); |
| 585 | return SET_LOCAL_DATE_VALUE(this, MakeDate(day, LOCAL_TIME_IN_DAY(this))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 586 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 587 | |
| 588 | |
| 589 | // ECMA 262 - 15.9.5.37 |
| 590 | function DateSetUTCDate(date) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 591 | var t = UTC_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 592 | date = ToNumber(date); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 593 | var day = MakeDay(UTC_YEAR(this), UTC_MONTH(this), date); |
| 594 | return SET_UTC_DATE_VALUE(this, MakeDate(day, UTC_TIME_IN_DAY(this))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 595 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 596 | |
| 597 | |
| 598 | // ECMA 262 - 15.9.5.38 |
| 599 | function DateSetMonth(month, date) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 600 | var t = LOCAL_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 601 | month = ToNumber(month); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 602 | date = %_ArgumentsLength() < 2 ? LOCAL_DAY(this) : ToNumber(date); |
| 603 | var day = MakeDay(LOCAL_YEAR(this), month, date); |
| 604 | return SET_LOCAL_DATE_VALUE(this, MakeDate(day, LOCAL_TIME_IN_DAY(this))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 605 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 606 | |
| 607 | |
| 608 | // ECMA 262 - 15.9.5.39 |
| 609 | function DateSetUTCMonth(month, date) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 610 | var t = UTC_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 611 | month = ToNumber(month); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 612 | date = %_ArgumentsLength() < 2 ? UTC_DAY(this) : ToNumber(date); |
| 613 | var day = MakeDay(UTC_YEAR(this), month, date); |
| 614 | return SET_UTC_DATE_VALUE(this, MakeDate(day, UTC_TIME_IN_DAY(this))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 615 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 616 | |
| 617 | |
| 618 | // ECMA 262 - 15.9.5.40 |
| 619 | function DateSetFullYear(year, month, date) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 620 | var t = LOCAL_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 621 | year = ToNumber(year); |
| 622 | var argc = %_ArgumentsLength(); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 623 | var time ; |
| 624 | if (NUMBER_IS_NAN(t)) { |
| 625 | month = argc < 2 ? 0 : ToNumber(month); |
| 626 | date = argc < 3 ? 1 : ToNumber(date); |
| 627 | time = 0; |
| 628 | } else { |
| 629 | month = argc < 2 ? LOCAL_MONTH(this) : ToNumber(month); |
| 630 | date = argc < 3 ? LOCAL_DAY(this) : ToNumber(date); |
| 631 | time = LOCAL_TIME_IN_DAY(this); |
| 632 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 633 | var day = MakeDay(year, month, date); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 634 | return SET_LOCAL_DATE_VALUE(this, MakeDate(day, time)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 635 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 636 | |
| 637 | |
| 638 | // ECMA 262 - 15.9.5.41 |
| 639 | function DateSetUTCFullYear(year, month, date) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 640 | var t = UTC_DATE_VALUE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 641 | year = ToNumber(year); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 642 | var argc = %_ArgumentsLength(); |
| 643 | var time ; |
| 644 | if (NUMBER_IS_NAN(t)) { |
| 645 | month = argc < 2 ? 0 : ToNumber(month); |
| 646 | date = argc < 3 ? 1 : ToNumber(date); |
| 647 | time = 0; |
| 648 | } else { |
| 649 | month = argc < 2 ? UTC_MONTH(this) : ToNumber(month); |
| 650 | date = argc < 3 ? UTC_DAY(this) : ToNumber(date); |
| 651 | time = UTC_TIME_IN_DAY(this); |
| 652 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 653 | var day = MakeDay(year, month, date); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 654 | return SET_UTC_DATE_VALUE(this, MakeDate(day, time)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 655 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 656 | |
| 657 | |
| 658 | // ECMA 262 - 15.9.5.42 |
| 659 | function DateToUTCString() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 660 | var t = UTC_DATE_VALUE(this); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 661 | if (NUMBER_IS_NAN(t)) return kInvalidDate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 662 | // Return UTC string of the form: Sat, 31 Jan 1970 23:00:00 GMT |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 663 | return WeekDays[UTC_WEEKDAY(this)] + ', ' |
| 664 | + TwoDigitString(UTC_DAY(this)) + ' ' |
| 665 | + Months[UTC_MONTH(this)] + ' ' |
| 666 | + UTC_YEAR(this) + ' ' |
| 667 | + TimeStringUTC(this) + ' GMT'; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 668 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 669 | |
| 670 | |
| 671 | // ECMA 262 - B.2.4 |
| 672 | function DateGetYear() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 673 | return LOCAL_YEAR(this) - 1900; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 674 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 675 | |
| 676 | |
| 677 | // ECMA 262 - B.2.5 |
| 678 | function DateSetYear(year) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 679 | CHECK_DATE(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 680 | year = ToNumber(year); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 681 | if (NUMBER_IS_NAN(year)) return SET_UTC_DATE_VALUE(this, $NaN); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 682 | year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) |
| 683 | ? 1900 + TO_INTEGER(year) : year; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 684 | var t = LOCAL_DATE_VALUE(this); |
| 685 | var month, date, time; |
| 686 | if (NUMBER_IS_NAN(t)) { |
| 687 | month = 0; |
| 688 | date = 1; |
| 689 | time = 0; |
| 690 | } else { |
| 691 | month = LOCAL_MONTH(this); |
| 692 | date = LOCAL_DAY(this); |
| 693 | time = LOCAL_TIME_IN_DAY(this); |
| 694 | } |
| 695 | var day = MakeDay(year, month, date); |
| 696 | return SET_LOCAL_DATE_VALUE(this, MakeDate(day, time)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | |
| 700 | // ECMA 262 - B.2.6 |
| 701 | // |
| 702 | // Notice that this does not follow ECMA 262 completely. ECMA 262 |
| 703 | // says that toGMTString should be the same Function object as |
| 704 | // toUTCString. JSC does not do this, so for compatibility we do not |
| 705 | // do that either. Instead, we create a new function whose name |
| 706 | // property will return toGMTString. |
| 707 | function DateToGMTString() { |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 708 | return %_CallFunction(this, DateToUTCString); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 709 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 710 | |
| 711 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 712 | function PadInt(n, digits) { |
| 713 | if (digits == 1) return n; |
| 714 | 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] | 715 | } |
| 716 | |
| 717 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 718 | // ECMA 262 - 15.9.5.43 |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 719 | function DateToISOString() { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 720 | var t = UTC_DATE_VALUE(this); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 721 | if (NUMBER_IS_NAN(t)) throw MakeRangeError("invalid_time_value", []); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 722 | var year = this.getUTCFullYear(); |
| 723 | var year_string; |
| 724 | if (year >= 0 && year <= 9999) { |
| 725 | year_string = PadInt(year, 4); |
| 726 | } else { |
| 727 | if (year < 0) { |
| 728 | year_string = "-" + PadInt(-year, 6); |
| 729 | } else { |
| 730 | year_string = "+" + PadInt(year, 6); |
| 731 | } |
| 732 | } |
| 733 | return year_string + |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 734 | '-' + PadInt(this.getUTCMonth() + 1, 2) + |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 735 | '-' + PadInt(this.getUTCDate(), 2) + |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 736 | 'T' + PadInt(this.getUTCHours(), 2) + |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 737 | ':' + PadInt(this.getUTCMinutes(), 2) + |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 738 | ':' + PadInt(this.getUTCSeconds(), 2) + |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 739 | '.' + PadInt(this.getUTCMilliseconds(), 3) + |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 740 | 'Z'; |
| 741 | } |
| 742 | |
| 743 | |
| 744 | function DateToJSON(key) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 745 | var o = ToObject(this); |
| 746 | var tv = DefaultNumber(o); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 747 | if (IS_NUMBER(tv) && !NUMBER_IS_FINITE(tv)) { |
| 748 | return null; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 749 | } |
| 750 | return o.toISOString(); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 754 | function ResetDateCache() { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 755 | // Reset the timezone cache: |
| 756 | timezone_cache_time = $NaN; |
| 757 | timezone_cache_timezone = undefined; |
| 758 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 759 | // Reset the date cache: |
| 760 | cache = Date_cache; |
| 761 | cache.time = $NaN; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 762 | cache.string = null; |
| 763 | } |
| 764 | |
| 765 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 766 | // ------------------------------------------------------------------- |
| 767 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 768 | function SetUpDate() { |
| 769 | %CheckIsBootstrapping(); |
| 770 | // Set up non-enumerable properties of the Date object itself. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 771 | InstallFunctions($Date, DONT_ENUM, $Array( |
| 772 | "UTC", DateUTC, |
| 773 | "parse", DateParse, |
| 774 | "now", DateNow |
| 775 | )); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 776 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 777 | // Set up non-enumerable constructor property of the Date prototype object. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 778 | %SetProperty($Date.prototype, "constructor", $Date, DONT_ENUM); |
| 779 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 780 | // Set up non-enumerable functions of the Date prototype object and |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 781 | // set their names. |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 782 | InstallFunctions($Date.prototype, DONT_ENUM, $Array( |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 783 | "toString", DateToString, |
| 784 | "toDateString", DateToDateString, |
| 785 | "toTimeString", DateToTimeString, |
| 786 | "toLocaleString", DateToLocaleString, |
| 787 | "toLocaleDateString", DateToLocaleDateString, |
| 788 | "toLocaleTimeString", DateToLocaleTimeString, |
| 789 | "valueOf", DateValueOf, |
| 790 | "getTime", DateGetTime, |
| 791 | "getFullYear", DateGetFullYear, |
| 792 | "getUTCFullYear", DateGetUTCFullYear, |
| 793 | "getMonth", DateGetMonth, |
| 794 | "getUTCMonth", DateGetUTCMonth, |
| 795 | "getDate", DateGetDate, |
| 796 | "getUTCDate", DateGetUTCDate, |
| 797 | "getDay", DateGetDay, |
| 798 | "getUTCDay", DateGetUTCDay, |
| 799 | "getHours", DateGetHours, |
| 800 | "getUTCHours", DateGetUTCHours, |
| 801 | "getMinutes", DateGetMinutes, |
| 802 | "getUTCMinutes", DateGetUTCMinutes, |
| 803 | "getSeconds", DateGetSeconds, |
| 804 | "getUTCSeconds", DateGetUTCSeconds, |
| 805 | "getMilliseconds", DateGetMilliseconds, |
| 806 | "getUTCMilliseconds", DateGetUTCMilliseconds, |
| 807 | "getTimezoneOffset", DateGetTimezoneOffset, |
| 808 | "setTime", DateSetTime, |
| 809 | "setMilliseconds", DateSetMilliseconds, |
| 810 | "setUTCMilliseconds", DateSetUTCMilliseconds, |
| 811 | "setSeconds", DateSetSeconds, |
| 812 | "setUTCSeconds", DateSetUTCSeconds, |
| 813 | "setMinutes", DateSetMinutes, |
| 814 | "setUTCMinutes", DateSetUTCMinutes, |
| 815 | "setHours", DateSetHours, |
| 816 | "setUTCHours", DateSetUTCHours, |
| 817 | "setDate", DateSetDate, |
| 818 | "setUTCDate", DateSetUTCDate, |
| 819 | "setMonth", DateSetMonth, |
| 820 | "setUTCMonth", DateSetUTCMonth, |
| 821 | "setFullYear", DateSetFullYear, |
| 822 | "setUTCFullYear", DateSetUTCFullYear, |
| 823 | "toGMTString", DateToGMTString, |
| 824 | "toUTCString", DateToUTCString, |
| 825 | "getYear", DateGetYear, |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 826 | "setYear", DateSetYear, |
| 827 | "toISOString", DateToISOString, |
| 828 | "toJSON", DateToJSON |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 829 | )); |
| 830 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 831 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 832 | SetUpDate(); |