2008-09-09 20:08:45 +00:00
|
|
|
// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
2008-10-03 18:00:28 +00:00
|
|
|
// This file relies on the fact that the following declarations have been made
|
|
|
|
// in v8natives.js:
|
2012-02-20 13:48:24 +00:00
|
|
|
// var $isFinite = GlobalIsFinite;
|
2008-10-03 18:00:28 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
|
|
// This file contains date support implemented in JavaScript.
|
|
|
|
|
|
|
|
// Keep reference to original values of some global properties. This
|
|
|
|
// has the added benefit that the code in this file is isolated from
|
|
|
|
// changes to these properties.
|
2012-02-20 13:48:24 +00:00
|
|
|
var $Date = global.Date;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-06-29 12:41:18 +00:00
|
|
|
// Helper function to throw error.
|
|
|
|
function ThrowDateTypeError() {
|
|
|
|
throw new $TypeError('this is not a Date object.');
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
var timezone_cache_time = $NaN;
|
|
|
|
var timezone_cache_timezone;
|
|
|
|
|
|
|
|
function LocalTimezone(t) {
|
2009-07-31 13:17:59 +00:00
|
|
|
if (NUMBER_IS_NAN(t)) return "";
|
2009-06-16 06:52:04 +00:00
|
|
|
if (t == timezone_cache_time) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return timezone_cache_timezone;
|
|
|
|
}
|
2012-03-09 12:07:29 +00:00
|
|
|
var timezone = %DateLocalTimezone(t);
|
2008-07-03 15:10:15 +00:00
|
|
|
timezone_cache_time = t;
|
|
|
|
timezone_cache_timezone = timezone;
|
|
|
|
return timezone;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
function UTC(time) {
|
2009-06-29 12:41:18 +00:00
|
|
|
if (NUMBER_IS_NAN(time)) return time;
|
2010-03-30 14:29:32 +00:00
|
|
|
// local_time_offset is needed before the call to DaylightSavingsOffset,
|
|
|
|
// so it may be uninitialized.
|
2012-03-09 12:07:29 +00:00
|
|
|
return %DateToUTC(time);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.1.11
|
|
|
|
function MakeTime(hour, min, sec, ms) {
|
|
|
|
if (!$isFinite(hour)) return $NaN;
|
|
|
|
if (!$isFinite(min)) return $NaN;
|
|
|
|
if (!$isFinite(sec)) return $NaN;
|
|
|
|
if (!$isFinite(ms)) return $NaN;
|
|
|
|
return TO_INTEGER(hour) * msPerHour
|
|
|
|
+ TO_INTEGER(min) * msPerMinute
|
|
|
|
+ TO_INTEGER(sec) * msPerSecond
|
|
|
|
+ TO_INTEGER(ms);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.1.12
|
|
|
|
function TimeInYear(year) {
|
|
|
|
return DaysInYear(year) * msPerDay;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Compute number of days given a year, month, date.
|
|
|
|
// Note that month and date can lie outside the normal range.
|
|
|
|
// For example:
|
|
|
|
// MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20)
|
|
|
|
// MakeDay(2007, -33, 1) --> MakeDay(2004, 3, 1)
|
|
|
|
// MakeDay(2007, 14, -50) --> MakeDay(2007, 8, 11)
|
|
|
|
function MakeDay(year, month, date) {
|
|
|
|
if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) return $NaN;
|
|
|
|
|
2010-07-02 20:09:33 +00:00
|
|
|
// Convert to integer and map -0 to 0.
|
|
|
|
year = TO_INTEGER_MAP_MINUS_ZERO(year);
|
|
|
|
month = TO_INTEGER_MAP_MINUS_ZERO(month);
|
|
|
|
date = TO_INTEGER_MAP_MINUS_ZERO(date);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-03-02 13:29:26 +00:00
|
|
|
if (year < kMinYear || year > kMaxYear ||
|
2011-10-28 08:45:04 +00:00
|
|
|
month < kMinMonth || month > kMaxMonth) {
|
2010-03-02 13:29:26 +00:00
|
|
|
return $NaN;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2011-10-28 08:45:04 +00:00
|
|
|
// Now we rely on year and month being SMIs.
|
2012-11-14 15:59:45 +00:00
|
|
|
return %DateMakeDay(year | 0, month | 0) + date - 1;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.1.13
|
|
|
|
function MakeDate(day, time) {
|
2010-12-16 13:02:09 +00:00
|
|
|
var time = day * msPerDay + time;
|
|
|
|
// Some of our runtime funtions for computing UTC(time) rely on
|
|
|
|
// times not being significantly larger than MAX_TIME_MS. If there
|
|
|
|
// is no way that the time can be within range even after UTC
|
|
|
|
// conversion we return NaN immediately instead of relying on
|
|
|
|
// TimeClip to do it.
|
|
|
|
if ($abs(time) > MAX_TIME_BEFORE_UTC) return $NaN;
|
|
|
|
return time;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.1.14
|
|
|
|
function TimeClip(time) {
|
|
|
|
if (!$isFinite(time)) return $NaN;
|
2010-12-16 13:02:09 +00:00
|
|
|
if ($abs(time) > MAX_TIME_MS) return $NaN;
|
2008-07-03 15:10:15 +00:00
|
|
|
return TO_INTEGER(time);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-07-07 11:57:09 +00:00
|
|
|
// The Date cache is used to limit the cost of parsing the same Date
|
|
|
|
// strings over and over again.
|
|
|
|
var Date_cache = {
|
|
|
|
// Cached time value.
|
|
|
|
time: $NaN,
|
|
|
|
// String input for which the cached time is valid.
|
|
|
|
string: null
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
%SetCode($Date, function(year, month, date, hours, minutes, seconds, ms) {
|
2009-07-03 10:09:59 +00:00
|
|
|
if (!%_IsConstructCall()) {
|
|
|
|
// ECMA 262 - 15.9.2
|
|
|
|
return (new $Date()).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.3
|
|
|
|
var argc = %_ArgumentsLength();
|
|
|
|
var value;
|
|
|
|
if (argc == 0) {
|
|
|
|
value = %DateCurrentTime();
|
2012-03-09 12:07:29 +00:00
|
|
|
SET_UTC_DATE_VALUE(this, value);
|
2009-07-03 10:09:59 +00:00
|
|
|
} else if (argc == 1) {
|
|
|
|
if (IS_NUMBER(year)) {
|
2012-03-09 12:07:29 +00:00
|
|
|
value = year;
|
2009-07-07 11:57:09 +00:00
|
|
|
} else if (IS_STRING(year)) {
|
|
|
|
// Probe the Date cache. If we already have a time value for the
|
|
|
|
// given time, we re-use that instead of parsing the string again.
|
|
|
|
var cache = Date_cache;
|
|
|
|
if (cache.string === year) {
|
|
|
|
value = cache.time;
|
|
|
|
} else {
|
|
|
|
value = DateParse(year);
|
2009-07-31 13:17:59 +00:00
|
|
|
if (!NUMBER_IS_NAN(value)) {
|
|
|
|
cache.time = value;
|
|
|
|
cache.string = year;
|
|
|
|
}
|
2009-07-07 11:57:09 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 10:09:59 +00:00
|
|
|
} else {
|
2008-07-03 15:10:15 +00:00
|
|
|
// According to ECMA 262, no hint should be given for this
|
2009-07-03 10:09:59 +00:00
|
|
|
// conversion. However, ToPrimitive defaults to STRING_HINT for
|
|
|
|
// Date objects which will lose precision when the Date
|
2008-07-03 15:10:15 +00:00
|
|
|
// constructor is called with another Date object as its
|
2009-07-03 10:09:59 +00:00
|
|
|
// argument. We therefore use NUMBER_HINT for the conversion,
|
|
|
|
// which is the default for everything else than Date objects.
|
|
|
|
// This makes us behave like KJS and SpiderMonkey.
|
2008-07-03 15:10:15 +00:00
|
|
|
var time = ToPrimitive(year, NUMBER_HINT);
|
2012-03-09 12:07:29 +00:00
|
|
|
value = IS_STRING(time) ? DateParse(time) : ToNumber(time);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2012-03-09 12:07:29 +00:00
|
|
|
SET_UTC_DATE_VALUE(this, value);
|
2009-07-03 10:09:59 +00:00
|
|
|
} else {
|
2008-07-03 15:10:15 +00:00
|
|
|
year = ToNumber(year);
|
|
|
|
month = ToNumber(month);
|
|
|
|
date = argc > 2 ? ToNumber(date) : 1;
|
|
|
|
hours = argc > 3 ? ToNumber(hours) : 0;
|
|
|
|
minutes = argc > 4 ? ToNumber(minutes) : 0;
|
|
|
|
seconds = argc > 5 ? ToNumber(seconds) : 0;
|
|
|
|
ms = argc > 6 ? ToNumber(ms) : 0;
|
2011-11-28 12:11:00 +00:00
|
|
|
year = (!NUMBER_IS_NAN(year) &&
|
|
|
|
0 <= TO_INTEGER(year) &&
|
|
|
|
TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year;
|
2008-07-03 15:10:15 +00:00
|
|
|
var day = MakeDay(year, month, date);
|
|
|
|
var time = MakeTime(hours, minutes, seconds, ms);
|
2012-03-09 12:07:29 +00:00
|
|
|
value = MakeDate(day, time);
|
|
|
|
SET_LOCAL_DATE_VALUE(this, value);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
%FunctionSetPrototype($Date, new $Date($NaN));
|
|
|
|
|
|
|
|
|
|
|
|
var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
2011-11-28 12:11:00 +00:00
|
|
|
var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
|
|
|
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
function TwoDigitString(value) {
|
|
|
|
return value < 10 ? "0" + value : "" + value;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2012-03-09 12:07:29 +00:00
|
|
|
function DateString(date) {
|
|
|
|
return WeekDays[LOCAL_WEEKDAY(date)] + ' '
|
|
|
|
+ Months[LOCAL_MONTH(date)] + ' '
|
|
|
|
+ TwoDigitString(LOCAL_DAY(date)) + ' '
|
|
|
|
+ LOCAL_YEAR(date);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2011-11-28 12:11:00 +00:00
|
|
|
var LongWeekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
|
|
|
|
'Thursday', 'Friday', 'Saturday'];
|
|
|
|
var LongMonths = ['January', 'February', 'March', 'April', 'May', 'June',
|
|
|
|
'July', 'August', 'September', 'October', 'November', 'December'];
|
2008-10-29 23:30:25 +00:00
|
|
|
|
|
|
|
|
2012-03-09 12:07:29 +00:00
|
|
|
function LongDateString(date) {
|
|
|
|
return LongWeekDays[LOCAL_WEEKDAY(date)] + ', '
|
|
|
|
+ LongMonths[LOCAL_MONTH(date)] + ' '
|
|
|
|
+ TwoDigitString(LOCAL_DAY(date)) + ', '
|
|
|
|
+ LOCAL_YEAR(date);
|
2008-10-29 23:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-09 12:07:29 +00:00
|
|
|
function TimeString(date) {
|
|
|
|
return TwoDigitString(LOCAL_HOUR(date)) + ':'
|
|
|
|
+ TwoDigitString(LOCAL_MIN(date)) + ':'
|
|
|
|
+ TwoDigitString(LOCAL_SEC(date));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2012-03-09 12:07:29 +00:00
|
|
|
function TimeStringUTC(date) {
|
|
|
|
return TwoDigitString(UTC_HOUR(date)) + ':'
|
|
|
|
+ TwoDigitString(UTC_MIN(date)) + ':'
|
|
|
|
+ TwoDigitString(UTC_SEC(date));
|
|
|
|
}
|
|
|
|
|
2010-03-31 12:20:32 +00:00
|
|
|
|
2012-03-09 12:07:29 +00:00
|
|
|
function LocalTimezoneString(date) {
|
|
|
|
var timezone = LocalTimezone(UTC_DATE_VALUE(date));
|
|
|
|
|
|
|
|
var timezoneOffset = -TIMEZONE_OFFSET(date);
|
2008-07-03 15:10:15 +00:00
|
|
|
var sign = (timezoneOffset >= 0) ? 1 : -1;
|
2008-10-07 10:54:50 +00:00
|
|
|
var hours = FLOOR((sign * timezoneOffset)/60);
|
|
|
|
var min = FLOOR((sign * timezoneOffset)%60);
|
2009-08-04 09:41:18 +00:00
|
|
|
var gmt = ' GMT' + ((sign == 1) ? '+' : '-') +
|
|
|
|
TwoDigitString(hours) + TwoDigitString(min);
|
2010-03-31 12:20:32 +00:00
|
|
|
return gmt + ' (' + timezone + ')';
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2012-03-09 12:07:29 +00:00
|
|
|
function DatePrintString(date) {
|
|
|
|
return DateString(date) + ' ' + TimeString(date);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
2009-07-07 11:57:09 +00:00
|
|
|
// Reused output buffer. Used when parsing date strings.
|
2010-05-03 06:43:25 +00:00
|
|
|
var parse_buffer = $Array(8);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// ECMA 262 - 15.9.4.2
|
|
|
|
function DateParse(string) {
|
2009-03-19 09:40:38 +00:00
|
|
|
var arr = %DateParseString(ToString(string), parse_buffer);
|
2008-07-03 15:10:15 +00:00
|
|
|
if (IS_NULL(arr)) return $NaN;
|
|
|
|
|
|
|
|
var day = MakeDay(arr[0], arr[1], arr[2]);
|
2010-05-03 06:43:25 +00:00
|
|
|
var time = MakeTime(arr[3], arr[4], arr[5], arr[6]);
|
2008-07-03 15:10:15 +00:00
|
|
|
var date = MakeDate(day, time);
|
2008-10-03 07:14:31 +00:00
|
|
|
|
2010-05-03 06:43:25 +00:00
|
|
|
if (IS_NULL(arr[7])) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return TimeClip(UTC(date));
|
|
|
|
} else {
|
2010-05-03 06:43:25 +00:00
|
|
|
return TimeClip(date - arr[7] * 1000);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.4.3
|
|
|
|
function DateUTC(year, month, date, hours, minutes, seconds, ms) {
|
|
|
|
year = ToNumber(year);
|
|
|
|
month = ToNumber(month);
|
|
|
|
var argc = %_ArgumentsLength();
|
|
|
|
date = argc > 2 ? ToNumber(date) : 1;
|
|
|
|
hours = argc > 3 ? ToNumber(hours) : 0;
|
|
|
|
minutes = argc > 4 ? ToNumber(minutes) : 0;
|
|
|
|
seconds = argc > 5 ? ToNumber(seconds) : 0;
|
|
|
|
ms = argc > 6 ? ToNumber(ms) : 0;
|
2011-11-28 12:11:00 +00:00
|
|
|
year = (!NUMBER_IS_NAN(year) &&
|
|
|
|
0 <= TO_INTEGER(year) &&
|
|
|
|
TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year;
|
2008-07-03 15:10:15 +00:00
|
|
|
var day = MakeDay(year, month, date);
|
|
|
|
var time = MakeTime(hours, minutes, seconds, ms);
|
2012-03-09 11:11:55 +00:00
|
|
|
return TimeClip(MakeDate(day, time));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Mozilla-specific extension. Returns the number of milliseconds
|
|
|
|
// elapsed since 1 January 1970 00:00:00 UTC.
|
|
|
|
function DateNow() {
|
2008-08-13 09:32:07 +00:00
|
|
|
return %DateCurrentTime();
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.2
|
|
|
|
function DateToString() {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this)
|
2009-06-29 12:41:18 +00:00
|
|
|
if (NUMBER_IS_NAN(t)) return kInvalidDate;
|
2012-03-09 12:07:29 +00:00
|
|
|
var time_zone_string = LocalTimezoneString(this)
|
|
|
|
return DatePrintString(this) + time_zone_string;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.3
|
|
|
|
function DateToDateString() {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this);
|
2009-06-29 12:41:18 +00:00
|
|
|
if (NUMBER_IS_NAN(t)) return kInvalidDate;
|
2012-03-09 12:07:29 +00:00
|
|
|
return DateString(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.4
|
|
|
|
function DateToTimeString() {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this);
|
2009-06-29 12:41:18 +00:00
|
|
|
if (NUMBER_IS_NAN(t)) return kInvalidDate;
|
2012-03-09 12:07:29 +00:00
|
|
|
var time_zone_string = LocalTimezoneString(this);
|
|
|
|
return TimeString(this) + time_zone_string;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.5
|
|
|
|
function DateToLocaleString() {
|
2011-01-28 10:33:10 +00:00
|
|
|
return %_CallFunction(this, DateToString);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.6
|
|
|
|
function DateToLocaleDateString() {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this);
|
2009-06-29 12:41:18 +00:00
|
|
|
if (NUMBER_IS_NAN(t)) return kInvalidDate;
|
2012-03-09 12:07:29 +00:00
|
|
|
return LongDateString(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-09-04 07:13:21 +00:00
|
|
|
// ECMA 262 - 15.9.5.7
|
|
|
|
function DateToLocaleTimeString() {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this);
|
2009-06-29 12:41:18 +00:00
|
|
|
if (NUMBER_IS_NAN(t)) return kInvalidDate;
|
2012-03-09 12:07:29 +00:00
|
|
|
return TimeString(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.8
|
|
|
|
function DateValueOf() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return UTC_DATE_VALUE(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-09-04 07:13:21 +00:00
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// ECMA 262 - 15.9.5.9
|
|
|
|
function DateGetTime() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return UTC_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.10
|
|
|
|
function DateGetFullYear() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return LOCAL_YEAR(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.11
|
|
|
|
function DateGetUTCFullYear() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return UTC_YEAR(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.12
|
|
|
|
function DateGetMonth() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return LOCAL_MONTH(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.13
|
|
|
|
function DateGetUTCMonth() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return UTC_MONTH(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.14
|
|
|
|
function DateGetDate() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return LOCAL_DAY(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.15
|
|
|
|
function DateGetUTCDate() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return UTC_DAY(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.16
|
|
|
|
function DateGetDay() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return LOCAL_WEEKDAY(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.17
|
|
|
|
function DateGetUTCDay() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return UTC_WEEKDAY(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.18
|
|
|
|
function DateGetHours() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return LOCAL_HOUR(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.19
|
|
|
|
function DateGetUTCHours() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return UTC_HOUR(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.20
|
|
|
|
function DateGetMinutes() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return LOCAL_MIN(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.21
|
|
|
|
function DateGetUTCMinutes() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return UTC_MIN(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.22
|
|
|
|
function DateGetSeconds() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return LOCAL_SEC(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.23
|
|
|
|
function DateGetUTCSeconds() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return UTC_SEC(this)
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.24
|
|
|
|
function DateGetMilliseconds() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return LOCAL_MS(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.25
|
|
|
|
function DateGetUTCMilliseconds() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return UTC_MS(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.26
|
|
|
|
function DateGetTimezoneOffset() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return TIMEZONE_OFFSET(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.27
|
|
|
|
function DateSetTime(ms) {
|
2012-03-09 12:07:29 +00:00
|
|
|
CHECK_DATE(this);
|
|
|
|
SET_UTC_DATE_VALUE(this, ToNumber(ms));
|
|
|
|
return UTC_DATE_VALUE(this);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.28
|
|
|
|
function DateSetMilliseconds(ms) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = LOCAL_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
ms = ToNumber(ms);
|
2012-03-09 12:07:29 +00:00
|
|
|
var time = MakeTime(LOCAL_HOUR(this), LOCAL_MIN(this), LOCAL_SEC(this), ms);
|
2012-03-26 10:13:03 +00:00
|
|
|
return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.29
|
|
|
|
function DateSetUTCMilliseconds(ms) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
ms = ToNumber(ms);
|
2012-03-09 12:07:29 +00:00
|
|
|
var time = MakeTime(UTC_HOUR(this),
|
|
|
|
UTC_MIN(this),
|
|
|
|
UTC_SEC(this),
|
2011-11-28 12:11:00 +00:00
|
|
|
ms);
|
2012-03-09 12:07:29 +00:00
|
|
|
return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.30
|
|
|
|
function DateSetSeconds(sec, ms) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = LOCAL_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
sec = ToNumber(sec);
|
2012-03-09 12:07:29 +00:00
|
|
|
ms = %_ArgumentsLength() < 2 ? LOCAL_MS(this) : ToNumber(ms);
|
|
|
|
var time = MakeTime(LOCAL_HOUR(this), LOCAL_MIN(this), sec, ms);
|
|
|
|
return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.31
|
|
|
|
function DateSetUTCSeconds(sec, ms) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
sec = ToNumber(sec);
|
2012-03-09 12:07:29 +00:00
|
|
|
ms = %_ArgumentsLength() < 2 ? UTC_MS(this) : ToNumber(ms);
|
|
|
|
var time = MakeTime(UTC_HOUR(this), UTC_MIN(this), sec, ms);
|
|
|
|
return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.33
|
|
|
|
function DateSetMinutes(min, sec, ms) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = LOCAL_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
min = ToNumber(min);
|
|
|
|
var argc = %_ArgumentsLength();
|
2012-03-09 12:07:29 +00:00
|
|
|
sec = argc < 2 ? LOCAL_SEC(this) : ToNumber(sec);
|
|
|
|
ms = argc < 3 ? LOCAL_MS(this) : ToNumber(ms);
|
|
|
|
var time = MakeTime(LOCAL_HOUR(this), min, sec, ms);
|
|
|
|
return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.34
|
|
|
|
function DateSetUTCMinutes(min, sec, ms) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
min = ToNumber(min);
|
|
|
|
var argc = %_ArgumentsLength();
|
2012-03-09 12:07:29 +00:00
|
|
|
sec = argc < 2 ? UTC_SEC(this) : ToNumber(sec);
|
|
|
|
ms = argc < 3 ? UTC_MS(this) : ToNumber(ms);
|
|
|
|
var time = MakeTime(UTC_HOUR(this), min, sec, ms);
|
|
|
|
return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.35
|
|
|
|
function DateSetHours(hour, min, sec, ms) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = LOCAL_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
hour = ToNumber(hour);
|
|
|
|
var argc = %_ArgumentsLength();
|
2012-03-09 12:07:29 +00:00
|
|
|
min = argc < 2 ? LOCAL_MIN(this) : ToNumber(min);
|
|
|
|
sec = argc < 3 ? LOCAL_SEC(this) : ToNumber(sec);
|
|
|
|
ms = argc < 4 ? LOCAL_MS(this) : ToNumber(ms);
|
2008-07-03 15:10:15 +00:00
|
|
|
var time = MakeTime(hour, min, sec, ms);
|
2012-03-09 12:07:29 +00:00
|
|
|
return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.34
|
|
|
|
function DateSetUTCHours(hour, min, sec, ms) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
hour = ToNumber(hour);
|
|
|
|
var argc = %_ArgumentsLength();
|
2012-03-09 12:07:29 +00:00
|
|
|
min = argc < 2 ? UTC_MIN(this) : ToNumber(min);
|
|
|
|
sec = argc < 3 ? UTC_SEC(this) : ToNumber(sec);
|
|
|
|
ms = argc < 4 ? UTC_MS(this) : ToNumber(ms);
|
2008-07-03 15:10:15 +00:00
|
|
|
var time = MakeTime(hour, min, sec, ms);
|
2012-03-09 12:07:29 +00:00
|
|
|
return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.36
|
|
|
|
function DateSetDate(date) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = LOCAL_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
date = ToNumber(date);
|
2012-03-09 12:07:29 +00:00
|
|
|
var day = MakeDay(LOCAL_YEAR(this), LOCAL_MONTH(this), date);
|
|
|
|
return SET_LOCAL_DATE_VALUE(this, MakeDate(day, LOCAL_TIME_IN_DAY(this)));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.37
|
|
|
|
function DateSetUTCDate(date) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
date = ToNumber(date);
|
2012-03-09 12:07:29 +00:00
|
|
|
var day = MakeDay(UTC_YEAR(this), UTC_MONTH(this), date);
|
|
|
|
return SET_UTC_DATE_VALUE(this, MakeDate(day, UTC_TIME_IN_DAY(this)));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.38
|
|
|
|
function DateSetMonth(month, date) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = LOCAL_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
month = ToNumber(month);
|
2012-03-09 12:07:29 +00:00
|
|
|
date = %_ArgumentsLength() < 2 ? LOCAL_DAY(this) : ToNumber(date);
|
|
|
|
var day = MakeDay(LOCAL_YEAR(this), month, date);
|
|
|
|
return SET_LOCAL_DATE_VALUE(this, MakeDate(day, LOCAL_TIME_IN_DAY(this)));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.39
|
|
|
|
function DateSetUTCMonth(month, date) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
month = ToNumber(month);
|
2012-03-09 12:07:29 +00:00
|
|
|
date = %_ArgumentsLength() < 2 ? UTC_DAY(this) : ToNumber(date);
|
|
|
|
var day = MakeDay(UTC_YEAR(this), month, date);
|
|
|
|
return SET_UTC_DATE_VALUE(this, MakeDate(day, UTC_TIME_IN_DAY(this)));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.40
|
|
|
|
function DateSetFullYear(year, month, date) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = LOCAL_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
year = ToNumber(year);
|
|
|
|
var argc = %_ArgumentsLength();
|
2012-03-09 12:07:29 +00:00
|
|
|
var time ;
|
|
|
|
if (NUMBER_IS_NAN(t)) {
|
|
|
|
month = argc < 2 ? 0 : ToNumber(month);
|
|
|
|
date = argc < 3 ? 1 : ToNumber(date);
|
|
|
|
time = 0;
|
|
|
|
} else {
|
|
|
|
month = argc < 2 ? LOCAL_MONTH(this) : ToNumber(month);
|
|
|
|
date = argc < 3 ? LOCAL_DAY(this) : ToNumber(date);
|
|
|
|
time = LOCAL_TIME_IN_DAY(this);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
var day = MakeDay(year, month, date);
|
2012-03-09 12:07:29 +00:00
|
|
|
return SET_LOCAL_DATE_VALUE(this, MakeDate(day, time));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.41
|
|
|
|
function DateSetUTCFullYear(year, month, date) {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
year = ToNumber(year);
|
2012-03-09 12:07:29 +00:00
|
|
|
var argc = %_ArgumentsLength();
|
|
|
|
var time ;
|
|
|
|
if (NUMBER_IS_NAN(t)) {
|
|
|
|
month = argc < 2 ? 0 : ToNumber(month);
|
|
|
|
date = argc < 3 ? 1 : ToNumber(date);
|
|
|
|
time = 0;
|
|
|
|
} else {
|
|
|
|
month = argc < 2 ? UTC_MONTH(this) : ToNumber(month);
|
|
|
|
date = argc < 3 ? UTC_DAY(this) : ToNumber(date);
|
|
|
|
time = UTC_TIME_IN_DAY(this);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
var day = MakeDay(year, month, date);
|
2012-03-09 12:07:29 +00:00
|
|
|
return SET_UTC_DATE_VALUE(this, MakeDate(day, time));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - 15.9.5.42
|
|
|
|
function DateToUTCString() {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this);
|
2009-06-29 12:41:18 +00:00
|
|
|
if (NUMBER_IS_NAN(t)) return kInvalidDate;
|
2008-07-03 15:10:15 +00:00
|
|
|
// Return UTC string of the form: Sat, 31 Jan 1970 23:00:00 GMT
|
2012-03-09 12:07:29 +00:00
|
|
|
return WeekDays[UTC_WEEKDAY(this)] + ', '
|
|
|
|
+ TwoDigitString(UTC_DAY(this)) + ' '
|
|
|
|
+ Months[UTC_MONTH(this)] + ' '
|
|
|
|
+ UTC_YEAR(this) + ' '
|
|
|
|
+ TimeStringUTC(this) + ' GMT';
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - B.2.4
|
|
|
|
function DateGetYear() {
|
2012-03-09 12:07:29 +00:00
|
|
|
return LOCAL_YEAR(this) - 1900;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - B.2.5
|
|
|
|
function DateSetYear(year) {
|
2012-03-09 12:07:29 +00:00
|
|
|
CHECK_DATE(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
year = ToNumber(year);
|
2012-03-09 12:07:29 +00:00
|
|
|
if (NUMBER_IS_NAN(year)) return SET_UTC_DATE_VALUE(this, $NaN);
|
2008-07-03 15:10:15 +00:00
|
|
|
year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99)
|
|
|
|
? 1900 + TO_INTEGER(year) : year;
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = LOCAL_DATE_VALUE(this);
|
|
|
|
var month, date, time;
|
|
|
|
if (NUMBER_IS_NAN(t)) {
|
|
|
|
month = 0;
|
|
|
|
date = 1;
|
|
|
|
time = 0;
|
|
|
|
} else {
|
|
|
|
month = LOCAL_MONTH(this);
|
|
|
|
date = LOCAL_DAY(this);
|
|
|
|
time = LOCAL_TIME_IN_DAY(this);
|
|
|
|
}
|
|
|
|
var day = MakeDay(year, month, date);
|
|
|
|
return SET_LOCAL_DATE_VALUE(this, MakeDate(day, time));
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ECMA 262 - B.2.6
|
|
|
|
//
|
|
|
|
// Notice that this does not follow ECMA 262 completely. ECMA 262
|
|
|
|
// says that toGMTString should be the same Function object as
|
|
|
|
// toUTCString. JSC does not do this, so for compatibility we do not
|
|
|
|
// do that either. Instead, we create a new function whose name
|
|
|
|
// property will return toGMTString.
|
|
|
|
function DateToGMTString() {
|
2011-01-28 10:33:10 +00:00
|
|
|
return %_CallFunction(this, DateToUTCString);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2010-01-14 08:55:15 +00:00
|
|
|
function PadInt(n, digits) {
|
|
|
|
if (digits == 1) return n;
|
|
|
|
return n < MathPow(10, digits - 1) ? '0' + PadInt(n, digits - 1) : n;
|
2009-04-24 08:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-28 08:45:04 +00:00
|
|
|
// ECMA 262 - 15.9.5.43
|
2009-04-24 08:13:09 +00:00
|
|
|
function DateToISOString() {
|
2012-03-09 12:07:29 +00:00
|
|
|
var t = UTC_DATE_VALUE(this);
|
2011-10-28 08:45:04 +00:00
|
|
|
if (NUMBER_IS_NAN(t)) throw MakeRangeError("invalid_time_value", []);
|
2011-07-01 11:41:45 +00:00
|
|
|
var year = this.getUTCFullYear();
|
|
|
|
var year_string;
|
|
|
|
if (year >= 0 && year <= 9999) {
|
|
|
|
year_string = PadInt(year, 4);
|
|
|
|
} else {
|
|
|
|
if (year < 0) {
|
|
|
|
year_string = "-" + PadInt(-year, 6);
|
|
|
|
} else {
|
|
|
|
year_string = "+" + PadInt(year, 6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return year_string +
|
2010-12-15 09:31:05 +00:00
|
|
|
'-' + PadInt(this.getUTCMonth() + 1, 2) +
|
2011-07-01 11:41:45 +00:00
|
|
|
'-' + PadInt(this.getUTCDate(), 2) +
|
2010-12-15 09:31:05 +00:00
|
|
|
'T' + PadInt(this.getUTCHours(), 2) +
|
2011-07-01 11:41:45 +00:00
|
|
|
':' + PadInt(this.getUTCMinutes(), 2) +
|
2010-12-15 09:31:05 +00:00
|
|
|
':' + PadInt(this.getUTCSeconds(), 2) +
|
2010-01-14 08:55:15 +00:00
|
|
|
'.' + PadInt(this.getUTCMilliseconds(), 3) +
|
2009-04-24 08:13:09 +00:00
|
|
|
'Z';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function DateToJSON(key) {
|
2010-12-15 09:31:05 +00:00
|
|
|
var o = ToObject(this);
|
|
|
|
var tv = DefaultNumber(o);
|
2011-07-01 11:41:45 +00:00
|
|
|
if (IS_NUMBER(tv) && !NUMBER_IS_FINITE(tv)) {
|
|
|
|
return null;
|
2010-12-15 09:31:05 +00:00
|
|
|
}
|
|
|
|
return o.toISOString();
|
2009-04-24 08:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-17 12:45:27 +00:00
|
|
|
function ResetDateCache() {
|
|
|
|
// Reset the timezone cache:
|
|
|
|
timezone_cache_time = $NaN;
|
|
|
|
timezone_cache_timezone = undefined;
|
|
|
|
|
|
|
|
// Reset the date cache:
|
|
|
|
cache = Date_cache;
|
|
|
|
cache.time = $NaN;
|
|
|
|
cache.string = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
function SetUpDate() {
|
|
|
|
%CheckIsBootstrapping();
|
|
|
|
// Set up non-enumerable properties of the Date object itself.
|
2008-10-03 07:14:31 +00:00
|
|
|
InstallFunctions($Date, DONT_ENUM, $Array(
|
|
|
|
"UTC", DateUTC,
|
|
|
|
"parse", DateParse,
|
|
|
|
"now", DateNow
|
|
|
|
));
|
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
// Set up non-enumerable constructor property of the Date prototype object.
|
2008-10-03 12:14:29 +00:00
|
|
|
%SetProperty($Date.prototype, "constructor", $Date, DONT_ENUM);
|
2008-10-03 07:14:31 +00:00
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
// Set up non-enumerable functions of the Date prototype object and
|
2009-05-04 19:35:46 +00:00
|
|
|
// set their names.
|
2011-11-15 09:44:57 +00:00
|
|
|
InstallFunctions($Date.prototype, DONT_ENUM, $Array(
|
2008-10-03 07:14:31 +00:00
|
|
|
"toString", DateToString,
|
|
|
|
"toDateString", DateToDateString,
|
|
|
|
"toTimeString", DateToTimeString,
|
|
|
|
"toLocaleString", DateToLocaleString,
|
|
|
|
"toLocaleDateString", DateToLocaleDateString,
|
|
|
|
"toLocaleTimeString", DateToLocaleTimeString,
|
|
|
|
"valueOf", DateValueOf,
|
|
|
|
"getTime", DateGetTime,
|
|
|
|
"getFullYear", DateGetFullYear,
|
|
|
|
"getUTCFullYear", DateGetUTCFullYear,
|
|
|
|
"getMonth", DateGetMonth,
|
|
|
|
"getUTCMonth", DateGetUTCMonth,
|
|
|
|
"getDate", DateGetDate,
|
|
|
|
"getUTCDate", DateGetUTCDate,
|
|
|
|
"getDay", DateGetDay,
|
|
|
|
"getUTCDay", DateGetUTCDay,
|
|
|
|
"getHours", DateGetHours,
|
|
|
|
"getUTCHours", DateGetUTCHours,
|
|
|
|
"getMinutes", DateGetMinutes,
|
|
|
|
"getUTCMinutes", DateGetUTCMinutes,
|
|
|
|
"getSeconds", DateGetSeconds,
|
|
|
|
"getUTCSeconds", DateGetUTCSeconds,
|
|
|
|
"getMilliseconds", DateGetMilliseconds,
|
|
|
|
"getUTCMilliseconds", DateGetUTCMilliseconds,
|
|
|
|
"getTimezoneOffset", DateGetTimezoneOffset,
|
|
|
|
"setTime", DateSetTime,
|
|
|
|
"setMilliseconds", DateSetMilliseconds,
|
|
|
|
"setUTCMilliseconds", DateSetUTCMilliseconds,
|
|
|
|
"setSeconds", DateSetSeconds,
|
|
|
|
"setUTCSeconds", DateSetUTCSeconds,
|
|
|
|
"setMinutes", DateSetMinutes,
|
|
|
|
"setUTCMinutes", DateSetUTCMinutes,
|
|
|
|
"setHours", DateSetHours,
|
|
|
|
"setUTCHours", DateSetUTCHours,
|
|
|
|
"setDate", DateSetDate,
|
|
|
|
"setUTCDate", DateSetUTCDate,
|
|
|
|
"setMonth", DateSetMonth,
|
|
|
|
"setUTCMonth", DateSetUTCMonth,
|
|
|
|
"setFullYear", DateSetFullYear,
|
|
|
|
"setUTCFullYear", DateSetUTCFullYear,
|
|
|
|
"toGMTString", DateToGMTString,
|
|
|
|
"toUTCString", DateToUTCString,
|
|
|
|
"getYear", DateGetYear,
|
2009-04-24 08:13:09 +00:00
|
|
|
"setYear", DateSetYear,
|
|
|
|
"toISOString", DateToISOString,
|
|
|
|
"toJSON", DateToJSON
|
2008-10-03 07:14:31 +00:00
|
|
|
));
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-09-05 07:30:35 +00:00
|
|
|
SetUpDate();
|