Repository navigation
Conversation
Add tests to isBefore and isAfter preparatory to fixing moment#2362, since moment.min and moment.max rely on isBefore and isAfter to calculate moment value
|
While you're in the neighborhood, would it make sense to treat |
|
@cwohlman you said you'd filter out invalid moments in the issue but now you return invalid If any one of them is invalid. Also you can change isSame isAfter and isBefore to return false if they hit invalid. |
|
Actually, as suggested here: #2362 (comment), I wrote the fix to match the Math.min and Math.max behavior. Also, I noticed that isBefore isAfter match the Math operations Although in my original use case I would have preferred for the invalid moments to be filtered out, I think this implementation makes more sense on the general principle that math operations involving NaN typically return NaN. |
I think that makes sense, the user can always filter out invalid moments before getting the min/max. |
|
So you only added tests for before/after methods -- so they just worked? Also can you please add isSame to the bunch? I agree that the filtering can be left out. |
|
I'd be happy to add isSame to this pull request, don't have time right this minute, but I'll try to get it in sometime today. |
this fixes an issue where isSame would return true for two invalid moments, which is inconsistent with NaN === NaN and also inconsistent with other cases where isSame would return false for two invalid moments. (some invalid moments are backed by a valid date) Fixes moment#2354
|
Note that my latest changes modify the behavior of moment.valueOf in cases where an invalid moment is backed by a valid date. |
|
@ichernev correct, the before and after methods already exhibited the correct behavior. |
|
@cwohlman would this "edge" case (invalid moment backed by valid date) happen if you create an invalid moment, but then modify it, in the current code? If yes, I'd say a lot of people "depend" on this functionality, i.e. we'll break a lot of code if we start propagating invalid moments. Also if there is valid date attached, all of the moment methods will just work correctly, and it will be almost unnoticeable (that the moment is invalid). |
|
@cwohlman thank you! Will merge in next release. |
|
Merged in c410da4 |
Fix inconsistent moment.min and moment.max results
Fixes #2362, includes updated tests for moment.min and moment.max.
Also includes tests to show that moment.isBefore and moment.isAfter correctly handle invalid moments.