mirror of
https://github.com/samsonjs/strftime.git
synced 2026-03-25 09:05:48 +00:00
don't check for Date instances, just required methods
This commit is contained in:
parent
403504a494
commit
8565e692a1
1 changed files with 14 additions and 1 deletions
15
lib/index.js
15
lib/index.js
|
|
@ -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>)
|
||||
|
|
|
|||
Loading…
Reference in a new issue