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

formatDate cannot parse valid value #1396

Closed
liemdo opened this issue Aug 8, 2019 · 2 comments
Closed

formatDate cannot parse valid value #1396

liemdo opened this issue Aug 8, 2019 · 2 comments

Comments

@liemdo
Copy link

liemdo commented Aug 8, 2019

I get error RangeError: Invalid time value when passing the timestamp to formatDate.

formatDate('2019-08-06T15:16:23.000Z')

However, this works fine:

formatDate(new Date('2019-08-06T15:16:23.000Z'))

Expected behavior

formatDate should be able to parse the timestamp

Current behavior

Get error RangeError: Invalid time value

Step to reproduce for BUG REPORT

Your Environment

Executable Version
npm ls react-intl 3.1.1
npm ls react 16.8.6
npm --version 6.9.0
node --version 12.4.0
OS Version
macOS Mojave 10.14.5
Browser Version
Chrome 75.0.3770.142
@longlho
Copy link
Member

longlho commented Aug 8, 2019

string Date parsing is inherently buggy & inconsistent cross browser so we typically recommend number instead. The native API itself doesn't take in string for this reason. There're also edge cases like '' where Intl.DateTimeFormat would treat like 0, but Date('') results in Invalid Date.

@longlho
Copy link
Member

longlho commented Aug 8, 2019 via email

@longlho longlho closed this as completed in aed8c68 Aug 8, 2019
github-merge-queue bot pushed a commit that referenced this issue Jan 2, 2025
This PR allows strings in `formatDateTimeRange`. The reason for this is
consistency.
Back in 2019, we added this to `formatDate` and `formatTime`.

Here are the issue and commits that originated this change:
- Issue: #1396
- Comit:
aed8c68#diff-41c7b3ac268a3a1ae5c7be92f1230f600013b7170e44a693570ccbdb183ea36bR95

Also, if you check the documentation on `formatDateTimeRange`, you would
be lead to error:

![image](/~https://github.com/user-attachments/assets/e41e9e37-9910-43ac-90cf-ad6e49aa6ec1)

Even though we see `number | Date | string`, strings don't work.
Right now we get error:
```
Uncaught Error: [@formatjs/intl Error FORMAT_ERROR] Error formatting date time range.
Locale: en-us


Invalid time value
RangeError: Invalid time value
```
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

2 participants