timezone transitions

by russau

CSS

div { font-family: monospace; }
span { color: red; }

JavaScript

var dt = new Date('Jan 1 2000 00:00:00 GMT+1000');



while (dt < new Date()) {

    var oneSecAgo = new Date(dt.getTime() - 1000);
    var offset1 = oneSecAgo.getTimezoneOffset();
    var offset2 = dt.getTimezoneOffset();

    if (offset1 != offset2) {
        $('body').append(oneSecAgo.toString());
        $('body').append('<br>');
        $('body').append(dt.toString());
        $('body').append('<br>');
        
        doCal(dt);
    }
    dt = new Date(dt.getTime() + 60 * 60 * 1000);


}




function doCal(date) {

    var monthNames = ["January", "February", "March", "April", "May", "June",
           "July", "August", "September", "October", "November", "December"];

    var first = new Date(date);
    var month = first.getMonth();
    first.setDate(1);

    $('body').append('<div>' + monthNames[first.getMonth()] + ' ' + first.getFullYear() + '</div>');
    $('body').append('<div>SS MM TT WW TT FF SS</div>');
    var nums = $('<div/>');
    $('body').append(nums);
    var d = 1;
    while (month == first.getMonth()) {

        if (d == 1) {
            for (var j = 0; j < first.getDay(); j++) {
                nums.append('&nbsp;&nbsp;&nbsp;');
            }
        }
        var dateNum = (new Date(date).getDate() == first.getDate()) ? "<span>" + leadingZeros(first.getDate(), 2) + "</span>" : leadingZeros(first.getDate(), 2);

        nums.append(dateNum + " ");
        if (first.getDay() == 6) nums.append('<br>');

        first.setDate(first.getDate() + 1);
        d++;
    }

}



function leadingZeros(num, totalChars, padWith) {
    num = num + "";
    padWith = (padWith) ? padWith : "0";
    if (num.length < totalChars) {
        while (num.length < totalChars) {
            num = padWith + num;
        }
    } else {}

    if (num.length > totalChars) { //if padWith was a multiple character string and num was overpadded
        num = num.substring((num.length - totalChars), totalChars);
    } else {}

    return num;
}