don't check for Date instances, just required methods

This commit is contained in:
Sami Samhuri 2013-03-02 11:09:00 -08:00
parent 403504a494
commit 8565e692a1

View file

@ -57,7 +57,7 @@
// locale is an object with the same structure as DefaultLocale
function _strftime(fmt, d, locale, _useUTC) {
// d and locale are optional so check if d is really the locale
if (d && !(d instanceof Date)) {
if (d && !quacksLikeDate(d)) {
locale = d;
d = undefined;
}
@ -135,6 +135,19 @@
});
}
RequiredDateMethods = ['getTime', 'getTimezoneOffset', 'getDay', 'getDate', 'getMonth', 'getFullYear', 'getYear', 'getHours', 'getMinutes', 'getSeconds'];
function quacksLikeDate(x) {
var i = 0
, n = RequiredDateMethods.length
;
for (i = 0; i < n; ++i) {
if (typeof x[RequiredDateMethods[i]] != 'function') {
return false;
}
}
return true;
}
// Default padding is '0' and default length is 2, both are optional.
function pad(n, padding, length) {
// pad(n, <length>)