isValid throws console.warn when pass the string
See original GitHub issueI’m trying to check the date is valid or not with isValid and it returns false when I pass the string eg. ‘2016-01-01’ But toDate function is still logging the two console warnings
First one:
Starting with v2.0.0-beta.1 date-fns doesn't accept strings as arguments. Please use "parseISO" to parse strings. See: https://git.io/fjule
Second one:
Error at toDate (index.js:50) at isValid (index.js:68) ...
I don’t know it’s intended or not but IMHO toDate should not throw warnings when isValid used.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Detecting an "invalid date" Date instance in JavaScript
Pass it a string parameter and it will determine whether it's a valid date or not based on this format "dd/MM/yyyy". here is...
Read more >console.warn() - Web APIs | MDN
The console.warn() method outputs a warning message to the Web ... A JavaScript string containing zero or more substitution strings.
Read more >Catch warnings in Jest tests | Ben Ilegbodu
warn ) when the type checking fails for a component. Because these types of warnings are console warnings and not thrown errors, developers...
Read more >The 10 Most Common JavaScript Issues Developers Face
All of these evaluate to 'true'! console.log(false == '0'); ... The alternative to passing a string as the first argument to these methods...
Read more >How to test custom prop validators in Vue.js - Vue School Blog
I advise against using this approach it('does not throw console error ... stringContaining('[Vue warn]: Invalid prop: custom validator check ...
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 Free
Top 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
I should also add to this that maybe date-fns should throw exceptions instead of polluting the console with warnings. I’m doing some code that try-catch a format() attempt, as I can’t be sure if the data I receive is a valid date or not (it can be a valid date, or a string with a valid date formatted, or a string that must pass as-is), then in the catch I handle the invalid cases. The problem is that, although my code works pretty well, date-fns constantly fills the console with huge dumps each time format function isn’t able to format the date. The catch prevents the exception to be written in the console, but the format function writing warnings escapes to my control. Isn’t there a “quiet” option to make it behave silently?
Well… passing it with parseISO makes no sens…
https://date-fns.org/v2.9.0/docs/isValid
you should change the documentation, or remove the error and just return false. Ofcourse in my opinion.