-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
toJSON throw exception instead of returns null #632
Comments
https://runkit.com/embed/tay2fpsxv5bz moment('').second(0) moment(null).second(0) also return Invalid Date |
@xxyuk I think guillaumebriday means that the I view the moment.js' source code. It will check the date is valid then choose to call
Should we also check its validity first by calling |
yep exactly @g1eny0ung ! I ended doing this in my own application : { due_at: dayjs(this.form.due_at).isValid() ? dayjs(this.form.due_at).second(0) : null } I will open a PR |
Describe the bug
There is a different behaviour between moment and dayjs when date is invalid and toJSON is called.
Expected behavior
It's annoying when you when to call an api with a nullable field, for example :
This code does not work if
this.form.due_at
is""
ornull
But this one works :
Thank you in advance
Information
The text was updated successfully, but these errors were encountered: