From 4765b4a02d9c92caa2c9738429175d98d310ef8f Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 6 Aug 2013 15:26:10 +0100 Subject: [PATCH] Use a more robust check for whether a variable is a date The simple "instanceof Date" check fails if the Date was made in a different node.js VM --- boot/boot.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/boot/boot.js b/boot/boot.js index 5961cd9f6..c0765e19d 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -76,6 +76,13 @@ $tw.utils.isArray = function(value) { return Object.prototype.toString.call(value) == "[object Array]"; }; +/* +Determine if a value is a date +*/ +$tw.utils.isDate = function(value) { + return Object.prototype.toString.call(value) === "[object Date]"; +}; + /* Iterate through all the own properties of an object or array. Callback is invoked with (element,title,object) */ @@ -240,7 +247,7 @@ $tw.utils.parseDate = function(value) { parseInt(value.substr(10,2)||"00",10), parseInt(value.substr(12,2)||"00",10), parseInt(value.substr(14,3)||"000",10))); - } else if (value instanceof Date) { + } else if ($tw.utils.isDate(value)) { return value; } else { return null;