-
-
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
Validation .isValid() doesn't work always #320
Comments
@dakshshah96 |
Moreover, |
You should not overestimate the quality of such validation. You will be able to catch nonsense like |
Is this an option to validate if date exist?
|
Thanks! It's very helpful. |
I'm just swapping over from Moment to DayJS. The unit tests I have in place to validate incorrect entries like 2000-02-31 by using |
facing same issue, isValid() always returns true const dayjs = require("dayjs")
console.log(dayjs('2021-15-35').isValid()) const dayjs = require("dayjs")
console.log(dayjs('2021-15-35', 'YYYY-MM-DD').isValid()) Expected: false Any suggestion? |
Turns out But not sure how... could somebody explain ? |
console.log(dayjs("2021-15-35", "YYYY-MM-DD").isValid()); // true
console.log(dayjs("35/15/2021", "DD/MM/YYYY").isValid()); // false So it is somehow related to the date format. |
@mateuszpigula passing a third parameter
I've tested a few cases including leap years, and this seems to work fine to check if the date actually exists. |
Why is this still closed? This issue cost me at least 4 hours because it is still broken. |
Such workaround only works for having DD and MM. Once you have non leading zero with D and M neither this approach nor the strict flag solves the issue. :( A fix to this could be to add a check to the customFormatParser if the date.getMonth() equals the parsed month. |
I get the same issue |
Any update on this ? I still get incorrect results (v1.11.3)
FYI - Adding |
That's still validating as true for me too |
This is the very first thing I've tried with Day.js and it's failed. I've installed the |
Why does dayjs require a special plugin just to validate if a month has a 31st day? |
Also, if you are having this problem check the parsing of your date:
If this occurs try adding an ext:
Hope this helped someone. |
The
.isValid()
validation doesn't function correctly under the following condition:Some instances where
.isValid()
returnstrue
for a date that is invalid:dayjs().isValid('1995-02-31')
dayjs().isValid('1995-03-31')
dayjs().isValid('1995-04-31')
dayjs().isValid('1995-06-31')
dayjs().isValid('1995-09-31')
dayjs().isValid('1995-11-31')
The text was updated successfully, but these errors were encountered: