question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

isValid throws console.warn when pass the string

See original GitHub issue

I’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:open
  • Created 4 years ago
  • Reactions:4
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
ropinheirocommented, Sep 17, 2020

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?

3reactions
Fortidudecommented, Jan 23, 2020

Well… passing it with parseISO makes no sens…

https://date-fns.org/v2.9.0/docs/isValid

Name Type Description
date * the date to check

you should change the documentation, or remove the error and just return false. Ofcourse in my opinion.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found