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.

parseISO with Date argument typings

See original GitHub issue

I have input coming from the server as Date object but in a certain case, the server input is replaced by a JSON file with the same data. But since this is JSON, Date’s are now strings.

parseISO still appears to work with Date as argument but the typings say the argument can only be string.

Is this just a missing type?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Christilutcommented, Jan 8, 2020

Ah that’s really good to know. Seems like better standard behavior than new Date too.

0reactions
kossnocorpcommented, Jan 8, 2020

Yeah, but also new Date parsing algo differs from a browser to browser, so we were getting many cross-browser bug reports from people parsing loose formats (e.g. Jan 14).

Another case to use parseISO is when you have an incomplete string. new Date('2019-01-01') will parse the date in UTC unlike parseISO that would return the date in the local timezone:

new Date('2019-01-01')
//=> Tue Jan 01 2019 04:00:00 GMT+0400 (Samara Standard Time)

new Date(2019, 0, 1)
//=> Tue Jan 01 2019 00:00:00 GMT+0400 (Samara Standard Time)

parseISO('2019-01-01')
//=> Tue Jan 01 2019 00:00:00 GMT+0400 (Samara Standard Time)
Read more comments on GitHub >

github_iconTop Results From Across the Web

date-fns: Difference between parseISO(string) and new Date ...
Docs for parseISO here. Basically parseISO tries to parse string which holds ISO formatted date string like '2019-09-25T14:34:32.999Z' .
Read more >
formatISO number of required arguments. typings vs ... - GitHub
This page says that formatISO requires only 1 argument: https://date-fns.org/v2.23.0/docs/formatISO But in the real world.
Read more >
date-fns - modern JavaScript date utility library
date -fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
Read more >
parseISO (JavaScript) - HCL Product Documentation
Represents a date and time. parseISO (JavaScript). Creates a Date object representing a specified time in ISO format.
Read more >
client/node_modules/date-fns/CHANGELOG.md - GitLab
From now on a string should be parsed using parseISO (ISO 8601) or parse . In v1 we've used new Date() to parse...
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