Wrong return type for parseISO
See original GitHub issueHi,
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:
- Created 2 years ago
- Comments:11 (4 by maintainers)
Top 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 >
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
@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.
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})$/.