-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Unhandled edge case for isValid() function. #6229
Comments
The point is that I would suggest, assuming your date string is stored in if (myStringDate && moment(myStringDate).isValid()) {
// Do whatever is needed when the date is valid
} Just in case you would prefer an early return pattern: if (!myStringDate || !moment(myStringDate).isValid()) {
return;
}
// Do whatever is needed when the date is valid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
I was using moment in my project. I wanted to use a if-condition that will execute a peice of code based on a condition that If the date string that I am getting is a valid date string then only it will proceed else it won't. But somehow the date string was coming undefined. Surprisingly, moment(undefined).isValid() was returning true. It should return false
To Reproduce
Steps to reproduce the behavior:
Just code this line : console.log(moment(undefined).isValid()); //output TRUE
Expected behavior
Output should be false.
Desktop (please complete the following information):
Moment-specific environment
Please run the following code in your environment and include the output:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: