Problem with isValid function
See original GitHub issueThere is an issue with the isValid function
The problem
💻 Code demonstrating the problem
isValid(new Date(‘2022-02-30’))
import { isValid } from 'date-fns'
isValid(new Date('2022-02-30'))
//=> Problematic output
Return true
### 🙁 Actual behavior
2.28.0
### 🙂 Expected behavior
<!-- Describe what you expected to get -->
## Debug information
- date-fns version: <!-- Fill in the date-fns version you use -->
- Browser/Node.js version: <!-- Fill in the envrionment version (i.e. Chrome 94.0.4606.61) -->
- Your timezone: <!-- Fill in your timezone name (i.e. Asia/Singapore) -->
- Your current time: <!-- Fill in the time when did you tested the probmlem (i.e. 16:20) -->
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
In the Transformer stage, using the IsValid function throws a ...
Problem. Using the IsValid function to check for a valid date. However, the function throws a warning if there is an actual bad...
Read more >moment.js isValid function not working properly - Stack Overflow
In your question you write that moment('03:55jojojo', 'HH:mm',true).isValid(); returns true. This is incorrect. Please check your jsfiddle ...
Read more >Validating data with the IsValid function and the cfparam tag
The IsValid function tests the value of a ColdFusion variable. If the value is valid, it returns True; if the value is invalid,...
Read more >Validation .isValid() doesn't work always · Issue #320 - GitHub
Some instances where . isValid() returns true for a date that is invalid: dayjs(). isValid('1995-02-31')
Read more >Issue with IsValid function with integer(int32) and decimal
IsValid ('int32', 2147483649) returns 0. IsValid() on int8 and int16 upper limits gives expected results. On int32 and int64 it appears to give ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think you’re correct the docs could be improved. go ahead and submit your PR.
Cheers @mandaputtra, will take a look ASAP.
For reference, looks like
isValid(anyString)
is false.In other words,
isValid("2022-02-30")
is false but so isisValid("2022-02-28")
. parseISO looks the way to go for this case.