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.

Wrong return type for parseISO

See original GitHub issue

Hi,

I use the parseISO function like this :

      const date = parseISO(val)
      if (date === "Invalid Date") return false

TS compiler returns an error because parseISO is supposed to return a Date. But in fact, it can return a string with the value “Invalid Date”.

In my idea, it would be better to return an exception. But at least, the definition should be : parseInfo(...): Date | string.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fturmelcommented, Sep 9, 2021

@marcbachmann If it’s good enough for your use case, that’s great.

I do think it’s important to point out these details for others stumbling on this issue in the future. They might not be running this in node exclusively, or might care about dates before 1970.

0reactions
pom421commented, Sep 10, 2021

For future reader, my need was to validate a date format in ISO in a payload API JSON, so I decided to not use date-fns but only use the regex : /^(\d{4})-(\d{2})-(\d{2})$/.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Date-fns parseISO returning wrong date - Stack Overflow
1. This is because of the return type of methods. format() return "an string" parseISO() returns "the parsed date in the local time...
Read more >
parseISO returning wrong time on day of offset change #1618
In Germany the offset will change from +1 to +2 on March 29th. When using parseISO on a timestamp on this day the...
Read more >
How to use the date-fns.parseISO function in date-fns | Snyk
parseISO examples, based on popular ways it is used in public projects. ... showDate?: boolean): string => { if (!useLocalTime) { return value;...
Read more >
How to parse ISO 8601 date in Swift - Sarunw
When parsing a date from a string, you might think of DateFormatter . You have to manually set dateFormat and locale to DateFormatter...
Read more >
Docs - Moment.js
If a string does not match any of the above formats and is not able to be parsed with Date.parse , moment#isValid will...
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