Parsing 'daylight saving date' returns wrong date and time on Android.
See original GitHub issue🐛 Bug Report
Parsing ‘daylight saving date’ returns wrong date and time on Android.
If a run:
console.log(new Date(2019,1,17));
In the browsers, or in node js, it returns Sun Feb 17 2019 00:00:00 GMT-0300 (Brasilia Standard Time)
.
But, in React Native app it returns Sat Feb 16 2019 23:00:00 GMT-0300 (-03)
.
Note thats the timezone is correct GMT-0300
, but the datetime returned is wrong.
The source problem here, is that the daylight saving date ended on February 17. So in ‘2019-02-17 00:00:00’ we had to go back an hour on the clock. Returning to ‘2019-01-16 23:00:00’.
To Reproduce
Setup the Android timezone to ‘America/Sao_Paulo GMT-03:00’ (-02:00 when in daylight saving date)
Run console.log(new Date(2019,1,17))
in a React Native app.
The output will be Sat Feb 16 2019 23:00:00 GMT-0300 (-03)
or 2019-02-17T03:00:00.000Z
.
Expected Behavior
The output should be Sun Feb 17 2019 00:00:00 GMT-0300 (Brasilia Standard Time)
.
Code Example
Strangely, using an Expo Snack the problem does not occur.
Snack: https://snack.expo.io/Bkj8saGIV
Environment
Tested with real devices with Android P, and with emulators API 16 and API 28.
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
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
Upgrading to the
jsc-android
following the instructions @douglasjunior posted resolved my issue (running RN 0.58.3)Yes, I also managed to solve by following the
jsc-android
installation instructions.Before I could not to solve due to some cache of Android Studio.