nodeunit icon indicating copy to clipboard operation
nodeunit copied to clipboard

Comparison of Date objects doesn't seem to work

Open keithhackbarth opened this issue 12 years ago • 1 comments

test.equal(new Date("3/29/2013 12:30:00 AM"), new Date("3/29/2013 12:30:00 AM"));

keithhackbarth avatar Apr 24 '13 17:04 keithhackbarth

Hi, this is as expected. Test equal uses the '==' operator to compare the object. The objects are both of the same type but not the same object! You can try this without nodeunit: var a = new Date("3/29/2013 12:30:00 AM"); var b = new Date("3/29/2013 12:30:00 AM"); a == b; // false a === b; // false

You could do something like this to compare them: a.toString() == b.toString(); // true Or even better a.getTime() == b.getTime(); // true

playerwtf avatar Jul 04 '13 18:07 playerwtf