Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When input not ISO8601 time string like 2023/11/11 to toDate will return wrong date #257

Open
a631953720 opened this issue Nov 16, 2023 · 0 comments

Comments

@a631953720
Copy link

Hi there,

I really appreciate this library for handling dates across different time zones.

Thans to the date-fns-tz developers for providing such a useful library.

I'm confused about the toDate function. When I input a string like 2023/11/11, which is not an ISO8601 time string, toDate returns 2022-12-31T16:00:00.000Z date.

I noticed that the datePattern in the splitDateString function returns a matched result as shown below:

const datePattern = new RegExp(/^([0-9W+-]+)(.*)/);

datePattern.exec('2023/11/11'); // [2023/11/11, 2023, /11/11, 0, 2023/11/11, undefined]

As a result, dateStrings.date only captures the year (2023), leading to date.setUTCFullYear(2023).

Is there any plan to either restrict or support this specific time string format?

This is my codeSendBox to present these different case result.

https://codesandbox.io/s/date-fns-tz-todate-4mql3c?file=/src/index.mjs

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant