react-native formatting is different - debug mode on/off #2841
-
There seems to be different formats for when debugging is on (development) and off (production) in react-native using the latest version of date-fns, any way to make them the same? i sense some inconsistencies will arise when shipping the app from development to production. I'm getting the error: Invalid time value. As shown in the video below I'm trying out this format: '2020-12-29 01:15:00' and calling isValid on it in both debug/no debug mode. Screen.Recording.2021-01-03.at.10.25.55.PM.mov |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Was there any update on this one? |
Beta Was this translation helpful? Give feedback.
-
I think this has noting to do with Screen.Recording.2021-06-22.at.12.55.20.PM.movThe problem is that you are using a string in the Date constructor, which can behave differently depending on the runtime. Per MDN:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date Couple solutions:
Good luck! |
Beta Was this translation helpful? Give feedback.
-
Some additional details on the React Native runtimes here: https://reactnative.dev/docs/javascript-environment#javascript-runtime Essentially, it's JavaScriptCore (Safari's JS engine) that runs prod and V8 (Chrome) while debugging. I get the exact same error in Safari. |
Beta Was this translation helpful? Give feedback.
-
Going to move this to a discussion so it's easier for people to find. |
Beta Was this translation helpful? Give feedback.
I think this has noting to do with
date-fns
. I could reproduce the behavior within the interactive code example in React Native's "get started" page just using a native Date object. Works on web, breaks on iOS.Screen.Recording.2021-06-22.at.12.55.20.PM.mov
The problem is that you are using a string in the Date constructor, which can behave differently depending on the runtime.
Per MDN:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
Couple solutions: