diff --git a/source/Ox/js/Date.js b/source/Ox/js/Date.js index 0eff3148..74668b2e 100644 --- a/source/Ox/js/Date.js +++ b/source/Ox/js/Date.js @@ -257,7 +257,7 @@ Ox.makeDate Takes a date, number or string, returns a date @*/ Ox.makeDate = function(date) { // Safari 4/5 (<= 534.59.10) doesn't parse YYYY, YYYY-MM or YYYY-MM-DD - if (Ox.isString(date)) { + if (Ox.isString(date) && Ox.isInvalidDate(new Date(date))) { if (/^\d{4}$/.test(date)) { date += '-01-01'; } else if (/^\d{4}-\d{2}$/.test(date)) { diff --git a/source/Ox/js/Type.js b/source/Ox/js/Type.js index 03aded5e..1bc09f73 100644 --- a/source/Ox/js/Type.js +++ b/source/Ox/js/Type.js @@ -241,6 +241,17 @@ Ox.isInt = function(value) { return isFinite(value) && value === Math.floor(value); }; +/* +Ox.isInvalidDate Tests if a value is an invalid date + (value) -> True if the value is an invalid date + value <*> Any value + > Ox.isInvalidDate(new Date('foo')) + true +*/ +Ox.isValidDate = function(value) { + return Ox.isDate(value) && Ox.isNaN(value.getTime()); +}; + /*@ Ox.isNaN Tests if a value is `NaN` (value) -> True if the value is `NaN` @@ -371,6 +382,17 @@ Ox.isUndefined = function(value) { return Ox.typeOf(value) == 'undefined'; }; +/* +Ox.isValidDate Tests if a value is a valid date + (value) -> True if the value is a valid date + value <*> Any value + > Ox.isValidDate(new Date()) + true +*/ +Ox.isValidDate = function(value) { + return Ox.isDate(value) && !Ox.isNaN(value.getTime()); +}; + /*@ Ox.typeOf Returns the type of a value (value) -> Type