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

This commit is contained in:
rolux 2012-05-27 15:05:24 +02:00
parent 4b8c1a7d6b
commit a34c406d78

View file

@ -185,20 +185,24 @@ Ox.getTime = function(utc) {
/*@ /*@
Ox.getTimezoneOffset <f> Get the local time zone offset in milliseconds Ox.getTimezoneOffset <f> Get the local time zone offset in milliseconds
([date]) -> <n> Offset in milliseconds
date <d|u> Return offset at this date (if undefined, return current offset)
@*/ @*/
Ox.getTimezoneOffset = function() { Ox.getTimezoneOffset = function(date) {
return new Date().getTimezoneOffset() * 60000; return Ox.makeDate(date).getTimezoneOffset() * 60000;
}; };
/*@ /*@
Ox.getTimezoneOffsetString <f> Get the local time zone offset as a string Ox.getTimezoneOffsetString <f> Get the local time zone offset as a string
Returns a time zone offset string (from around '-1200' to around '+1200'). Returns a time zone offset string (from around '-1200' to around '+1200').
([date]) -> <s> Offset as a string
date <d|u> Return offset at this date (if undefined, return current offset)
> Ox.getTimezoneOffsetString(new Date('01/01/2000')).length > Ox.getTimezoneOffsetString(new Date('01/01/2000')).length
5 5
@*/ @*/
Ox.getTimezoneOffsetString = function(date) { Ox.getTimezoneOffsetString = function(date) {
var offset = (Ox.makeDate(date)).getTimezoneOffset(); var offset = Ox.makeDate(date).getTimezoneOffset();
return (offset < 0 ? '+' : '-') return (offset <= 0 ? '+' : '-')
+ Ox.pad(Math.floor(Math.abs(offset) / 60), 2) + Ox.pad(Math.floor(Math.abs(offset) / 60), 2)
+ Ox.pad(Math.abs(offset) % 60, 2); + Ox.pad(Math.abs(offset) % 60, 2);
}; };
@ -235,12 +239,12 @@ Ox.isLeapYear = function(year, utc) {
/*@ /*@
Ox.makeDate <f> Takes a date, number or string, returns a date Ox.makeDate <f> Takes a date, number or string, returns a date
> Ox.formatDate(Ox.makeDate(new Date('01/01/1970')), '%m/%d/%Y') > Ox.formatDate(Ox.makeDate(0), '%m/%d/%Y', true)
'01/01/1970'
> Ox.formatDate(Ox.makeDate(0), '%m/%d/%Y')
'01/01/1970' '01/01/1970'
> Ox.formatDate(Ox.makeDate('01/01/1970'), '%m/%d/%Y') > Ox.formatDate(Ox.makeDate('01/01/1970'), '%m/%d/%Y')
'01/01/1970' '01/01/1970'
> Ox.formatDate(Ox.makeDate(new Date('01/01/1970')), '%m/%d/%Y')
'01/01/1970'
@*/ @*/
Ox.makeDate = function(date) { Ox.makeDate = function(date) {
// if date is a date, new Date(date) makes a clone // if date is a date, new Date(date) makes a clone