Skip to content
This repository

Date comparison functions #257

Closed
icambron opened this Issue · 3 comments

2 participants

Isaac Cambron Tim Wood
Isaac Cambron
Collaborator

Would you accept these additions if I made them?

aMoment.isBefore(otherMoment);         //=> true or false
aMoment.isAfter(otherMoment);            //=> true or false
aMoment.compareTo(otherMoment);  //=> -1,0, or 1

If so, do you think it would be best to wrap the parameter with a moment(otherMoment) call so you could pass in strings too? My bias is to do exactly that.

Tim Wood
Owner

You can just do moment(a) > moment(b). The valueOf prototype method makes this possible.

Isaac Cambron
Collaborator

TIL. That's pretty cool on JS's part, and it's a bit weird that I didn't know that. Glad I asked before writing the code.

Isaac Cambron icambron closed this
Tim Wood
Owner

Yeah, I end up using it a lot with arithmetic functions, like in moment.fn.diff.

Here's some cool articles where I first learned about valueOf.

http://webreflection.blogspot.com/2010/10/javascript-coercion-demystified.html
http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.