hermes: MM/DD/YYYY format leads to invalid date

Bug Description

When using dates like 12/12/2022 or 11/30/2000 00:00:00, I get Date invalid.

While I know that this is a non-standard date format, both JSC and V8 support these date formats.

I’m also happy to submit a PR to fix this, so long as the team is okay with it.

This ticket is a duplicate of #647, which seems to have been closed errantly.

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

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

Steps To Reproduce

  1. new Date("12/12/2022")
  2. See Invalid Date when logging to console.log

code example:

The Expected Behavior

It should parse as December 12th, 2022.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 4
  • Comments: 18 (6 by maintainers)

Most upvoted comments

I feel really bad about saying this but as a rule you should probably just stick to the standard or revise the standard.

There will always be some edge case applying to some International time zone/user-input/server-timezone that will slip through and the divergence between V8 / JSC and Hermes could probably cause immense chaos when porting that will only show up at some random date and time.

It might be better to just mask the user input and output in and out of the desired format and forward the parsing to the well tested standard functions.

You and other contributors to this might also probably have a major implementation conflict every time for the parsing of the edge case, the pros/cons between selection of the V8 versus JSC parsing implementation and here is where an definite standard would be really useful.

@vksgautam1986 Could you please show me how you are doing in code, and what the date format is coming, in the above comments I’ve given you the example only.

also, follow the below link doc of Momentjs https://momentjs.com/docs/#/parsing/string-format/

@ayelenguini you need parse your date if the date format is NON-RFC/ISO8601. configure your moment as below mentioned moment(date, 'MM/DD/YYYY').format('MM/DD/YYYY') as you see I’ve given the 2nd argument in the moment method this is required if your date format does not fall under RFC/ISO8601.

Hi! Any updates on this? I have an app that consumes a service with that type of date and after upgrading the RN from 69.2 to 72.2 it’s broken and shows Invalid Date. I’m using MM/DD/YYYY format date. Any workarounds that could be done from the frontend side are also welcome.