arshaw / xdate

A Modern JavaScript Date Library
http://arshaw.com/xdate/
GNU General Public License v2.0
681 stars 81 forks source link

Comparator support? #30

Closed valioDOTch closed 9 years ago

valioDOTch commented 9 years ago

It seems that the common comparators are not fully supported.

var tomorrow =  XDate.today(); tomorrow.setDate(tomorrow.getDate()+1);
XDate.today()>tomorrow; //returns false as expected
XDate.today()==tomorrow; //returns false as expected
XDate.today()<tomorrow; //returns true as expected
XDate.today()==XDate.today(); //returns false (and we're not even going for type comparison)

So are we supposed to do comparisons solely with diffXxx functions?

arshaw commented 9 years ago

yes, using the diff* functions is your best bet because it takes into account ambiguous timezones as well.

however, you can do the comparisons you want w/o them. you just need to cast to an int first, so prepend with +.

more info here: http://arshaw.com/xdate/#Inconsistencies