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.

Problem with isValid function

See original GitHub issue

There 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:open
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mandaputtracommented, Dec 15, 2022

I think you’re correct the docs could be improved. go ahead and submit your PR.

0reactions
robationscommented, Dec 15, 2022

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 is isValid("2022-02-28"). parseISO looks the way to go for this case.

Read more comments on GitHub >

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

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