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
print-window-tiddler
Jeremy Ruston 2013-08-06 15:26:10 +01:00
rodzic 6a75a62b16
commit 4765b4a02d
1 zmienionych plików z 8 dodań i 1 usunięć

Wyświetl plik

@ -76,6 +76,13 @@ $tw.utils.isArray = function(value) {
return Object.prototype.toString.call(value) == "[object Array]"; 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) 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(10,2)||"00",10),
parseInt(value.substr(12,2)||"00",10), parseInt(value.substr(12,2)||"00",10),
parseInt(value.substr(14,3)||"000",10))); parseInt(value.substr(14,3)||"000",10)));
} else if (value instanceof Date) { } else if ($tw.utils.isDate(value)) {
return value; return value;
} else { } else {
return null; return null;