hermes: Some date formats that worked in JSC fail with Hermes

Bug Description

When using dates like on the web, for example: 11/30/2000 00:00:00 I get “Invalid Date”

  • I have run gradle clean and confirmed this bug does not occur with JSC

Hermes version: 0.9.0 React Native version (if any): 0.66.1 OS version (if any): Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64):

Steps To Reproduce

  1. Pass the format '11/30/2021 00:00:00" in the Javascript Date Builder
  2. Show result on console

More infos

I tried to rewrite the Date constructor but I get the following message: RangeError: “Date value out of bounds, js engine: hermes”

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 13
  • Comments: 25 (9 by maintainers)

Most upvoted comments

@luizsn000 I don’t think we have addressed this yet?

We are looking into this and will implement a fix in Hermes. We are trying to understand why this is format is considered valid by other engines - Month/Day/Year is very US-centric and doesn’t make sense in Europe.

I am also curious to understand the use case for this rather illogical format. Which APIs return non-localized date strings in US format? Isn’t that a bug in those APIs?

To be clear, we will match what other engines are doing, but I am trying to better understand the root of the problem.

@luizsn000, please reopen this ticket - as it’s not resolved yet.

If you’d like to avoid getting notifications, you can do so on the sidebar, like so

image

I had to use this approach:

if (hini instanceof Date && !isNaN(hini) && hfin instanceof Date && !isNaN(hfin)) {
  ...
}

Now is working ✅

What’s causing the error is when I use .toISOString() to format the date.

Example: new Date("2023-12-12").toISOString()

@tmikov could you try to reproduce with this example?

This is preventing us from merging Hermes into our application.

Our backend returns a string of 11/30/2000, and we’re using DayJS to format that into something displayed by the end user. DayJS uses native Date constructors under the hood and, after a bit of debugging, ran into this issue.

Would you all be open to receiving a PR that enables this date format?