Add work around for YYYY and YYYY-MM dates for Safari, fixes #2329

This commit is contained in:
j 2014-02-18 10:59:58 +00:00
parent 48ce6fc101
commit ec3a077c2e

View file

@ -247,15 +247,23 @@ Ox.makeDate <f> Takes a date, number or string, returns a date
'01/01/1970' '01/01/1970'
> Ox.formatDate(Ox.makeDate('1970-01-01'), '%Y-%m-%d') > Ox.formatDate(Ox.makeDate('1970-01-01'), '%Y-%m-%d')
'1970-01-01' '1970-01-01'
> Ox.formatDate(Ox.makeDate('1970'), '%Y')
'1970'
> Ox.formatDate(Ox.makeDate('1970-05'), '%Y-%m')
'1970-05'
@*/ @*/
Ox.makeDate = function(date) { Ox.makeDate = function(date) {
//Safari 4/5 does not parse YYYY, YYYY-MM or YYYY-MM-DD as date
if ($.browser.safari && $.browser.version <= '534.59.10' && Ox.isString(date)) {
if (/^\d{4}$/.test(date)) {
date += '-01-01';
} else if (/^\d{4}-\d{2}$/.test(date)) {
date += '-01';
}
date = date.replace(/-/g, '/');
}
// if date is a date, new Date(date) makes a clone // if date is a date, new Date(date) makes a clone
return Ox.isUndefined(date) ? new Date() : new Date( return Ox.isUndefined(date) ? new Date() : new Date(date);
//Safari 4/5 does not understand YYYY-MM-DD format
$.browser.safari && $.browser.version <= '534.59.10' && Ox.isString(date)
? date.replace(/-/g, '/')
: date
);
}; };
/*@ /*@