mirror of https://github.com/tc39/test262.git
Found more of Sputnik's date helper funcs.
This commit is contained in:
parent
0b0736cbee
commit
17c67df352
|
@ -1,6 +1,69 @@
|
|||
// Copyright 2009 the Sputnik authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
//the following values are normally generated by the sputnik.py driver
|
||||
var $LocalTZ,
|
||||
$DST_start_month,
|
||||
$DST_start_sunday,
|
||||
$DST_start_hour,
|
||||
$DST_start_minutes,
|
||||
$DST_end_month,
|
||||
$DST_end_sunday,
|
||||
$DST_end_hour,
|
||||
$DST_end_minutes;
|
||||
|
||||
(function () {
|
||||
/**
|
||||
* Finds the first date, starting from |start|, where |predicate|
|
||||
* holds.
|
||||
*/
|
||||
var findNearestDateBefore = function(start, predicate) {
|
||||
var current = start;
|
||||
var month = 1000 * 60 * 60 * 24 * 30;
|
||||
for (var step = month; step > 0; step = Math.floor(step / 3)) {
|
||||
if (!predicate(current)) {
|
||||
while (!predicate(current))
|
||||
current = new Date(current.getTime() + step);
|
||||
current = new Date(current.getTime() - step);
|
||||
}
|
||||
}
|
||||
while (!predicate(current)) {
|
||||
current = new Date(current.getTime() + 1);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
var juneDate = new Date(2000, 6, 20, 0, 0, 0, 0);
|
||||
var decemberDate = new Date(2000, 12, 20, 0, 0, 0, 0);
|
||||
var juneOffset = juneDate.getTimezoneOffset();
|
||||
var decemberOffset = decemberDate.getTimezoneOffset();
|
||||
var isSouthernHemisphere = (juneOffset > decemberOffset);
|
||||
var winterTime = isSouthernHemisphere ? juneDate : decemberDate;
|
||||
var summerTime = isSouthernHemisphere ? decemberDate : juneDate;
|
||||
|
||||
$LocalTZ = new Date().getTimezoneOffset() / -60;
|
||||
|
||||
|
||||
var dstStart = findNearestDateBefore(winterTime, function (date) {
|
||||
return date.getTimezoneOffset() == summerTime.getTimezoneOffset();
|
||||
});
|
||||
$DST_start_month = dstStart.getMonth();
|
||||
$DST_start_sunday = dstStart.getDate() > 15 ? '"last"' : '"first"';
|
||||
$DST_start_hour = dstStart.getHours();
|
||||
$DST_start_minutes = dstStart.getMinutes();
|
||||
|
||||
var dstEnd = findNearestDateBefore(summerTime, function (date) {
|
||||
return date.getTimezoneOffset() == winterTime.getTimezoneOffset();
|
||||
});
|
||||
$DST_end_month = dstEnd.getMonth();
|
||||
$DST_end_sunday = dstEnd.getDate() > 15 ? '"last"' : '"first"';
|
||||
$DST_end_hour = dstEnd.getHours();
|
||||
$DST_end_minutes = dstEnd.getMinutes();
|
||||
|
||||
return;
|
||||
})();
|
||||
|
||||
|
||||
//15.9.1.2 Day Number and Time within Day
|
||||
function Day(t) {
|
||||
return Math.floor(t/msPerDay);
|
||||
|
@ -323,19 +386,4 @@ function ConstructDate(year, month, date, hours, minutes, seconds, ms){
|
|||
var r11 = MakeDate(r9, r10);
|
||||
|
||||
return TimeClip(UTC(r11));
|
||||
}
|
||||
|
||||
|
||||
//the following values are normally generated by the sputnik.py driver
|
||||
// for now, we'll just use 0 for everything
|
||||
/*
|
||||
var $LocalTZ=-8;
|
||||
var $DST_start_month=2;
|
||||
var $DST_start_sunday='first';
|
||||
var $DST_start_hour=2;
|
||||
var $DST_start_minutes=0;
|
||||
var $DST_end_month=10;
|
||||
var $DST_end_sunday='first';
|
||||
var $DST_end_hour=2;
|
||||
var $DST_end_minutes=0;
|
||||
*/
|
||||
}
|
Loading…
Reference in New Issue