Skip to content
Snippets Groups Projects
Commit 17c67df3 authored by David Fugate's avatar David Fugate
Browse files

Found more of Sputnik's date helper funcs.

parent 0b0736cb
No related branches found
No related tags found
No related merge requests found
// Copyright 2009 the Sputnik authors. All rights reserved. // Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file. // 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 //15.9.1.2 Day Number and Time within Day
function Day(t) { function Day(t) {
return Math.floor(t/msPerDay); return Math.floor(t/msPerDay);
...@@ -323,19 +386,4 @@ function ConstructDate(year, month, date, hours, minutes, seconds, ms){ ...@@ -323,19 +386,4 @@ function ConstructDate(year, month, date, hours, minutes, seconds, ms){
var r11 = MakeDate(r9, r10); var r11 = MakeDate(r9, r10);
return TimeClip(UTC(r11)); return TimeClip(UTC(r11));
} }
\ No newline at end of file
//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;
*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment