function InLeapYear(time) {
- return DaysInYear(YEAR_FROM_TIME(time)) == 366 ? 1 : 0;
+ return DaysInYear(YearFromTime(time)) == 366 ? 1 : 0;
}
function DayWithinYear(time) {
- return DAY(time) - DayFromYear(YEAR_FROM_TIME(time));
+ return DAY(time) - DayFromYear(YearFromTime(time));
}
// the actual year if it is in the range 1970..2037
if (t >= 0 && t <= 2.1e12) return t;
- var day = MakeDay(EquivalentYear(YEAR_FROM_TIME(t)),
- MONTH_FROM_TIME(t),
- DATE_FROM_TIME(t));
+ var day = MakeDay(EquivalentYear(YearFromTime(t)),
+ MonthFromTime(t),
+ DateFromTime(t));
return MakeDate(day, TimeWithinDay(t));
}
function LocalTimeNoCheck(time) {
var ltc = ltcache;
if (%_ObjectEquals(time, ltc.key)) return ltc.val;
- if (time < -MAX_TIME_MS || time > MAX_TIME_MS) {
- return $NaN;
- }
// Inline the DST offset cache checks for speed.
// The cache is hit, or DaylightSavingsOffset is called,
// ECMA 262 - 15.9.1.13
function MakeDate(day, time) {
- if (!$isFinite(day)) return $NaN;
- if (!$isFinite(time)) return $NaN;
- return day * msPerDay + time;
+ 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;
}
// ECMA 262 - 15.9.1.14
function TimeClip(time) {
if (!$isFinite(time)) return $NaN;
- if ($abs(time) > 8.64E15) return $NaN;
+ if ($abs(time) > MAX_TIME_MS) return $NaN;
return TO_INTEGER(time);
}
value = DateParse(year);
if (!NUMBER_IS_NAN(value)) {
cache.time = value;
- cache.year = YEAR_FROM_TIME(LocalTimeNoCheck(value));
+ cache.year = YearFromTime(LocalTimeNoCheck(value));
cache.string = year;
}
}
if (NUMBER_IS_NAN(t)) return t;
var cache = Date_cache;
if (cache.time === t) return cache.year;
- return YEAR_FROM_TIME(LocalTimeNoCheck(t));
+ return YearFromTime(LocalTimeNoCheck(t));
}
function DateGetUTCFullYear() {
var t = DATE_VALUE(this);
if (NUMBER_IS_NAN(t)) return t;
- return YEAR_FROM_TIME(t);
+ return YearFromTime(t);
}
function DateGetMonth() {
var t = DATE_VALUE(this);
if (NUMBER_IS_NAN(t)) return t;
- return MONTH_FROM_TIME(LocalTimeNoCheck(t));
+ return MonthFromTime(LocalTimeNoCheck(t));
}
function DateGetUTCMonth() {
var t = DATE_VALUE(this);
if (NUMBER_IS_NAN(t)) return t;
- return MONTH_FROM_TIME(t);
+ return MonthFromTime(t);
}
function DateGetDate() {
var t = DATE_VALUE(this);
if (NUMBER_IS_NAN(t)) return t;
- return DATE_FROM_TIME(LocalTimeNoCheck(t));
+ return DateFromTime(LocalTimeNoCheck(t));
}
function DateSetDate(date) {
var t = LocalTime(DATE_VALUE(this));
date = ToNumber(date);
- var day = MakeDay(YEAR_FROM_TIME(t), MONTH_FROM_TIME(t), date);
+ var day = MakeDay(YearFromTime(t), MonthFromTime(t), date);
return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t)))));
}
function DateSetUTCDate(date) {
var t = DATE_VALUE(this);
date = ToNumber(date);
- var day = MakeDay(YEAR_FROM_TIME(t), MONTH_FROM_TIME(t), date);
+ var day = MakeDay(YearFromTime(t), MonthFromTime(t), date);
return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t))));
}
var t = LocalTime(DATE_VALUE(this));
month = ToNumber(month);
date = %_ArgumentsLength() < 2 ? NAN_OR_DATE_FROM_TIME(t) : ToNumber(date);
- var day = MakeDay(YEAR_FROM_TIME(t), month, date);
+ var day = MakeDay(YearFromTime(t), month, date);
return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t)))));
}
var t = DATE_VALUE(this);
month = ToNumber(month);
date = %_ArgumentsLength() < 2 ? NAN_OR_DATE_FROM_TIME(t) : ToNumber(date);
- var day = MakeDay(YEAR_FROM_TIME(t), month, date);
+ var day = MakeDay(YearFromTime(t), month, date);
return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t))));
}
t = NUMBER_IS_NAN(t) ? 0 : LocalTimeNoCheck(t);
year = ToNumber(year);
var argc = %_ArgumentsLength();
- month = argc < 2 ? MONTH_FROM_TIME(t) : ToNumber(month);
- date = argc < 3 ? DATE_FROM_TIME(t) : ToNumber(date);
+ month = argc < 2 ? MonthFromTime(t) : ToNumber(month);
+ date = argc < 3 ? DateFromTime(t) : ToNumber(date);
var day = MakeDay(year, month, date);
return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t)))));
}
if (NUMBER_IS_NAN(t)) t = 0;
var argc = %_ArgumentsLength();
year = ToNumber(year);
- month = argc < 2 ? MONTH_FROM_TIME(t) : ToNumber(month);
- date = argc < 3 ? DATE_FROM_TIME(t) : ToNumber(date);
+ month = argc < 2 ? MonthFromTime(t) : ToNumber(month);
+ date = argc < 3 ? DateFromTime(t) : ToNumber(date);
var day = MakeDay(year, month, date);
return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t))));
}
if (NUMBER_IS_NAN(t)) return kInvalidDate;
// Return UTC string of the form: Sat, 31 Jan 1970 23:00:00 GMT
return WeekDays[WeekDay(t)] + ', '
- + TwoDigitString(DATE_FROM_TIME(t)) + ' '
- + Months[MONTH_FROM_TIME(t)] + ' '
- + YEAR_FROM_TIME(t) + ' '
+ + TwoDigitString(DateFromTime(t)) + ' '
+ + Months[MonthFromTime(t)] + ' '
+ + YearFromTime(t) + ' '
+ TimeString(t) + ' GMT';
}
function DateGetYear() {
var t = DATE_VALUE(this);
if (NUMBER_IS_NAN(t)) return $NaN;
- return YEAR_FROM_TIME(LocalTimeNoCheck(t)) - 1900;
+ return YearFromTime(LocalTimeNoCheck(t)) - 1900;
}
if (NUMBER_IS_NAN(year)) return %_SetValueOf(this, $NaN);
year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99)
? 1900 + TO_INTEGER(year) : year;
- var day = MakeDay(year, MONTH_FROM_TIME(t), DATE_FROM_TIME(t));
+ var day = MakeDay(year, MonthFromTime(t), DateFromTime(t));
return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t)))));
}
// Modified test from WebKit
// LayoutTests/fast/js/script-tests/date-utc-timeclip.js:
-assertEquals(Date.UTC(275760, 8, 12, 23, 59, 59, 999), 8639999999999999);
-assertEquals(Date.UTC(275760, 8, 13), 8640000000000000);
+assertEquals(8639999999999999, Date.UTC(275760, 8, 12, 23, 59, 59, 999));
+assertEquals(8640000000000000, Date.UTC(275760, 8, 13));
assertTrue(isNaN(Date.UTC(275760, 8, 13, 0, 0, 0, 1)));
assertTrue(isNaN(Date.UTC(275760, 8, 14)));
assertEquals(Date.UTC(-271821, 3, 20), -8640000000000000);
assertTrue(isNaN(Date.UTC(-271821, 3, 19, 23, 59, 59, 999)));
assertTrue(isNaN(Date.UTC(-271821, 3, 19)));
+
+
+// Test creation of large date values.
+d = new Date(1969, 12, 1, 99999999999);
+assertTrue(isNaN(d.getTime()));
+d = new Date(1969, 12, 1, -99999999999);
+assertTrue(isNaN(d.getTime()));
+d = new Date(1969, 12, 1, Infinity);
+assertTrue(isNaN(d.getTime()));
+d = new Date(1969, 12, 1, -Infinity);
+assertTrue(isNaN(d.getTime()));