New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
isSameOrAfter gives random output when comparing moment() to moment() #3781
Comments
Probably I have the same kind of issue. It is working as expected on chrome and Android device but not in iOS.
in iOS I am getting array null while it is working on chrome and Android. Environment: Cordova CLI: 6.4.0 |
Yes, I don't know what to tell you. This is just how finite-resolution datetimes have to work; "now" means a different time based on when you say it. |
@imrvshah First note that ...isSameOrAfter(moment().format('MM-DD-YYYY')) creates a new moment with the current time, formats it as a string, and passes that string to ...isSameOrAfter(moment()) And saved the moment -> string -> moment work. That's much better code, but I'd also bet it fixes the bug. Have you noticed deprecation warnings saying "hey, you're not supposed to pass strings to moment like that"? Moment knows how to parse ISO 8601 strings like m.isSameOrAfter("05-25-1982");
m.isSameOrAfter(moment("05-25-1982"))
m.isSameOrAfter(moment(new Date("05-25-1982"))) There's a reason we deprecated that: it gives inconsistent results based on what browser is running it. So what you're running into is that iOS doesn't support that format natively. In my Safari dev console: > new Date("05-25-1982")
Invalid Date That gave you bad comparisons that left you with an empty array. |
I agree with you and figure out the case in a console it was deprecation warning because of date format. Thanks for your comment about not wrapping it multiple times and just use. |
Description
So, me and a colleague found a bug in our code which turned out to be caused by us using an undefined variable (basically
moment(undefined)
and then trying to compare that to a new moment instance (moment()
) with the methodisSameOrAfter
.So what we basically used, was this:
Running that code once or twice is gonna return
true
, but not always. Once in a while it returnsfalse
, I guess it's because creating two instances of moment, after each other, with no time defined might create them with a few microseconds difference.Here's a test I ran in both Node v7.1.0 on Windows 10 and in Chrome/56.0.2924.87 with Moment.js 2.17.1.
The first two function will log
false
a few times out of 1000, and the third function won't. It only logs when it comes upon an exception.Environment:
Tue Feb 21 2017 14:36:06 GMT+0100 (W. Europe Standard Time)
2017-02-21 14:36:06
-60
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
2.17.1
The text was updated successfully, but these errors were encountered: