I couldn't find any comparison method like two DateTimes, if one is before or after from another.
Momentjs has query functions: http://momentjs.com/docs/#/query/
Will be similar functions in Luxon?
And what is the best way to compare two DateTime instances for now?
Use natural js comparison operators like >, <=, etc.
Yup, @woozyking is right. I'm going to leave this open to figure out where to document those. Probably deserves an entry in the "Math" page of the guide
馃憤 Thank you very much. I think Math section is good.
I also think these words would be useful for people who tries to 'search' (like Ctrl+F): compare, comparison, after, before
Updated the docs in 3918e6b. Will get pushed to the website next time I cut a release.
+d1 === +d2 // are d1 and d2 the same instant in time?
This looks ugly... Like incapsulation violation - knowledge that valueOf returns something useful and unary plus sign for calling it...
valueOf returning a number that is useful and being involved by the unary + is just how JS works. Your complaint is really with JS; Luxon is just following its idioms.
This is meant as a warning I imagine.
Since < and other math comparison operators are available, one may be tempted to use == or === for equality test. As pointed out, this will usually not work as expected with these immutable objects.
The idiomatic way of testing for equality is probably d1.equals(d2),
or if you are only interested in raw timestamps, d1.toMillis() === d2.toMillis()
valueOfreturning a number that is useful and being involved by the unary+is just how JS works. Your complaint is really with JS; Luxon is just following its idioms.
Yep, I don't like the unary plus in general, that's true. I don't like all that silly magic, that JS developers love (double negotiation, boolean "or" in non-boolean context and so on and so forth). Anyway, JS doesn't support operator overloading, so I don't think that using a "hack" with valueOf is obvious and expected, otherwise there wouldn't be this issue :wink:
I wish there were ordinary comparison methods...
Most helpful comment
Use natural js comparison operators like
>,<=, etc.