From a34c406d780716c2f1ccd74b8c4d0e4e49f2a233 Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 27 May 2012 15:05:24 +0200 Subject: [PATCH] Date.js: add the missing date argument to Ox.getTimezoneOffset (the current timezone's offset may have been different in the past); return '+0000', not '-0000', in Ox.getTimezoneOffsetString; correct a test for Ox.makeDate --- source/Ox/js/Date.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/source/Ox/js/Date.js b/source/Ox/js/Date.js index 1fd7e85a..ceb34ac0 100644 --- a/source/Ox/js/Date.js +++ b/source/Ox/js/Date.js @@ -185,20 +185,24 @@ Ox.getTime = function(utc) { /*@ Ox.getTimezoneOffset Get the local time zone offset in milliseconds + ([date]) -> Offset in milliseconds + date Return offset at this date (if undefined, return current offset) @*/ -Ox.getTimezoneOffset = function() { - return new Date().getTimezoneOffset() * 60000; +Ox.getTimezoneOffset = function(date) { + return Ox.makeDate(date).getTimezoneOffset() * 60000; }; /*@ Ox.getTimezoneOffsetString Get the local time zone offset as a string Returns a time zone offset string (from around '-1200' to around '+1200'). + ([date]) -> Offset as a string + date Return offset at this date (if undefined, return current offset) > Ox.getTimezoneOffsetString(new Date('01/01/2000')).length 5 @*/ Ox.getTimezoneOffsetString = function(date) { - var offset = (Ox.makeDate(date)).getTimezoneOffset(); - return (offset < 0 ? '+' : '-') + var offset = Ox.makeDate(date).getTimezoneOffset(); + return (offset <= 0 ? '+' : '-') + Ox.pad(Math.floor(Math.abs(offset) / 60), 2) + Ox.pad(Math.abs(offset) % 60, 2); }; @@ -235,12 +239,12 @@ Ox.isLeapYear = function(year, utc) { /*@ Ox.makeDate Takes a date, number or string, returns a date - > Ox.formatDate(Ox.makeDate(new Date('01/01/1970')), '%m/%d/%Y') - '01/01/1970' - > Ox.formatDate(Ox.makeDate(0), '%m/%d/%Y') + > Ox.formatDate(Ox.makeDate(0), '%m/%d/%Y', true) '01/01/1970' > Ox.formatDate(Ox.makeDate('01/01/1970'), '%m/%d/%Y') '01/01/1970' + > Ox.formatDate(Ox.makeDate(new Date('01/01/1970')), '%m/%d/%Y') + '01/01/1970' @*/ Ox.makeDate = function(date) { // if date is a date, new Date(date) makes a clone