Top.Mail.Ru
? ?

Oct. 31st, 2007

Baby in car

Javascript Puzzle

Here's my code:
var date1 = new Date();
date1.setFullYear(year1, month1 - 1, day1);
date1.setHours(0);
date1.setMinutes(0);
date1.setSeconds(0);
date1.setMilliseconds(0);

// repeat for date2 with different input fields

result = (date1 == date2);


Here's what the debugger (Firebug) shows:
result: false
date1: "Tue Oct 02 2007 00:00:00 GMT-0400 (Eastern Daylight Time)"
date2: "Tue Oct 02 2007 00:00:00 GMT-0400 (Eastern Daylight Time)"
(date1 == date2): false
(date1 != date2): true
(date1 <= date2): true
(date1 >= date2): true
(date1 <  date2): false
(date1 >  date2): false
(date1.toString() == date2.toString()): true


This code preforms as expected for all other comparisons (i.e., when I have two dates that are different, they show up as the correct kind of different).

Since the toString comparison works, I'll just toss that in the code for now, but it bothers me.