Join GitHub today
Fix inconsistent moment.min and moment.max results #2438
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.
@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).