Parsing 'daylight saving date' returns wrong date and time
douglasjunior opened this issue · comments
Issue Description
I found a critical problem with 'daylight saving' date parsing, which has affected all our apps.
If I do this console.log(new Date(2019,1,17))
, it prints Sat Feb 16 2019 23:00:00 GMT-0300 (-03)
, while the correct would:
- Browser:
Sun Feb 17 2019 00:00:00 GMT-0300
America/Sao_Paulo - NodeJS:
2019-02-17T03:00:00.000Z
UTC
Originally I have reported the problem on the RN repository at facebook/react-native#23657, but seems that this is related to JavaScriptCore.
I know that the problems is related to the old versions, so I am looking for a way to use the most recent version of the jsc-android
in RN old versions. Today we have projects in RN 0.52, 0.53, 0.54 and 0.57.
I've already followed the README instructions, the project runs, but the date problem continues.
I've create a sample project to simulate the problem, and to try to configure the new jsc-android
: https://github.com/douglasjunior/react-native-daylight-saving-date (the project is using RN 0.58 and jsc-android
236355.1.1 )
Version, config, any additional info
React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: (4) x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
Memory: 187.17 MB / 8.00 GB
Shell: 3.0.0 - /usr/local/bin/fish
Binaries:
Node: 8.14.0 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.5.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
Android SDK:
API Levels: 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28
Build Tools: 23.0.1, 23.0.3, 24.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.0, 28.0.0, 28.0.1, 28.0.2, 28.0.3
System Images: android-16 | Google APIs Intel x86 Atom, android-17 | Google APIs Intel x86 Atom, android-19 | Google APIs Intel x86 Atom, android-21 | Google APIs Intel x86 Atom, android-24 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5014246
Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
npmPackages:
react: 16.6.3 => 16.6.3
react-native: 0.58.5 => 0.58.5
npmGlobalPackages:
react-native-cli: 2.0.1
Could you please try with the Intl version if this will solve your problem?
https://github.com/react-native-community/jsc-android-buildscripts#international-variant
Note: Please do not tried on RN 0.59, the current method to adopt jsc-android-buildscripts is broken on RN 0.59 AFAIK.
I've tried with the International Variant:
All my projects are RN <= 0.58, and this is the sample project:
As I mentioned in this comment, in RN 0.59 the problem does not happen.
Probably because they are using a newer version of JavaScriptCore.
RN 0.59 in fact uses JavaScriptCore from this repo (jsc-android version 236355.1.1). And AFAIK, RN 0.59 uses the no-intl version and I expects there's no locale/Intl support.
So, it is really weird to me if you could solve the problem by using RN 0.59.
It may seem strange, but in RN 0.59 the problem does not occur.
I hope someone can help me find a solution because I have no idea where I should start.
I managed to make this work now. Seems to be a problem with Android Studio (or gradle) cache.
After close Android Studio and re-configure the new jsc-android
version, the problem was solved for RN 0.58.
I created a separated branch to reproduce the problema master
and others with the solution jsc
here: https://github.com/douglasjunior/react-native-daylight-saving-date
Thanks for your time!
Hi, @douglasjunior , @Kudo
I have a similar problem on Android only and I couldn't resolve that after a week! can you help me, please?
I'm using RN v0.63.4
which is uses jsc-android v245459.0.0
by default and it seems a newer version you used in this comment.
The Problem is when I create a date object from '2021/3/22'
using new Date('2021/3/22')
, it returns me '2021-03-21T19:30:00.000Z' on android and returns 2021/03/22T01:00:00.000Z
on iOS which the iOS result is the correct on. (my device timezone is on Tehran)
What should I do to get the correct adjusted result in Android?
Thanks