Permalink
Browse files

don't check for Date instances, just required methods

  • Loading branch information...
1 parent 403504a commit 8565e692a146459880babf3aa6fbe00d71127c41 @samsonjs committed Mar 2, 2013
Showing with 14 additions and 1 deletion.
  1. +14 −1 lib/index.js
View
@@ -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>)

0 comments on commit 8565e69

Please sign in to comment.