Skip to content
This repository

Date comparison functions #257

icambron opened this Issue · 3 comments

2 participants

Isaac Cambron Tim Wood
Isaac Cambron

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

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

Isaac Cambron

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

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.

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.