From 8565e692a146459880babf3aa6fbe00d71127c41 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sat, 2 Mar 2013 11:09:00 -0800 Subject: [PATCH] don't check for Date instances, just required methods --- lib/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 8b50dde..d448d8d 100644 --- a/lib/index.js +++ b/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, )