question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewzeycommented, Mar 10, 2019

Upgrading to the jsc-android following the instructions @douglasjunior posted resolved my issue (running RN 0.58.3)

0reactions
douglasjuniorcommented, Mar 11, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android: Daylight Saving Time issues - Stack Overflow
It will output incorrect time, that in one hour smaller. ... Z"); Date date = dateFormat.parse(dateStr); Log.v(TAG, "Date: " + date); ...
Read more >
If you can't change the time or time zone on your Apple device
You can use Date & Time settings to have your device adjust automatically for time zone changes and daylight saving time. If the...
Read more >
Date - JavaScript - MDN Web Docs - Mozilla
Chrome Edge Date Full support. Chrome1. Toggle history Full support. Edge12. Toggle hist... @@toPrimitive Full support. Chrome47. Toggle history Full support. Edge15. Toggle hist... Date() constructor...
Read more >
TimeZone - Android Developers
The TimeZone that is returned when you specify a custom time zone ID uses the specified offset from GMT(=UTC) and does not observe...
Read more >
Demystifying DateTime Manipulation in JavaScript - Toptal
They greatly simplify date parsing, date arithmetic and logical operations, ... Countries can decide to change their time zone offsets for Daylight Savings...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found