React-native: Time zone offset not detected on Android device

Created on 6 Sep 2017  路  16Comments  路  Source: facebook/react-native

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

  1. react-native -v: 0.46.0
  2. node -v:v8.2.1
  3. npm -v:3.10.10
  4. yarn --version:0.27.5

Then, specify:

  • Target Platform: iOS and Android

  • Development Operating System: macOs sierra 10.12.6

  • Build tools: Webstorm, issue only happens on Android devices (my app targets Android 7.0 and highers).

Steps to Reproduce

(Write your steps here:)

  1. Set your device time with a timezone offset (GMT +2 in my case);
  2. create a new Date (const date = new Date();)
  3. call getTimezoneOffset() on your date.

Expected Behavior

I expected my time zone offset to have 120 as value.

Actual Behavior

I get a "0" offset, as if my device timezone had not been detected.
The only way to get my timezone detected is to add a call to "toLocaleString()" function on my date, and then, my timezone offset is correct. I don't undersand the interactions between "getTimezoneOffset()" and "toLocaleString()".

Reproducible Demo

(Paste the link to an example project and exact instructions to reproduce the issue.)

Stale

Most helpful comment

Hello there, this issue should be re-opened :) I can confirm this issue happens on Samsung devices (tested on Galaxy S7 & S8). On a Nexus 5X, there is no problem. Tested on RN v.0.50.3

All 16 comments

0.48 is the newest version, can you try with the latest release and update your issue accordingly if it repros?

We're seeing this as well on 0.48.3. I'll try to update to 0.50 to see if it's fixed in that release.

I have noticed this, and it doesn't happen on all Android devices. When it does happen though, it's a really bad bug for the user.

For my app, I can consistently reproduce on a Samsung Galaxy S7 with Android 7.0 installed. I'm aware that some of my app's users have also experienced it on Huawei devices. All times displayed to the user in my app are off by three hours into the future. The device shows the correct time in the OS home screen, but times in the React Native app are off.

We are using React Native 49. Restarting the React Native app does not resolve the issue.

I can also confirm this. Only way to fix it after this happens is to reboot the phone.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

Hello there, this issue should be re-opened :) I can confirm this issue happens on Samsung devices (tested on Galaxy S7 & S8). On a Nexus 5X, there is no problem. Tested on RN v.0.50.3

馃憤 for re-opening the issue. Happens on Motorola devices too (along with the devices reported earlier). Tested till RN v0.51.0
Considering a large number of devices reported, this must be fixed asap.

I (actually my customer :( ) am having this issue with RN v0.53.3 on Android.

Tested with RN v0.52 in my company, and it works on some android devices, doesn't work on some (particularly it consistently doesn't work on Chromebook devices).

Same here, i'm using RN v0.55.3 on Android 7 and zebra devices.
When app is in debug this issue happens almost alway in the fist 15 minutes, after this time the app get right time.

This issue is always reproducible in Samsung devices.

Did anyone manage to get this working? This is a really irritating bug. I am using RN v0.55.4. This is happening for MI devices

We just followed what was posted by @victoriaBoucher and for us it worked quite well:

Actual Behavior
(...)
The only way to get my timezone detected is to add a call to "toLocaleString()" function on my date, and then, my timezone offset is correct. I don't undersand the interactions between "getTimezoneOffset()" and "toLocaleString()".

So we just put this line of code in the file that defines our outermost component, so that it is run as soon as the App is imported:

// yes, this is a silly line hanging by itself
new Date().toLocaleString();

And that fixed things. No idea why, and if it handles all the scenarios, but we didn't have any issues after that.

I am facing another weird problem with new Date() in some android devices only, not in iOS.

Suppose current time in my phone is 11:55 AM (GMT+5:30). Initially new Date( ).getMinutes() returns correct minutes (55 in this case), but when I go to Date & Time Settings in my Phone and change the time zone to GMT-04:00 (2:26 AM) ,I still get the old time in console (Reactotron console). Restarting the phone apparently seem to fix this bug.

Please note that I am not using chrome debugging for logging current time. I am using Reactotron for logging. I am using RN 0.55.4 and android device MI Redmi 4. But this is happening on Samsung devices as well.

I have tried using moment also but that too didn't help. I don't want to write a native module for such a trivial task

Any thoughts?

I'm using RN 0.57.0 and I'm still facing this issue about changing Time zone.
Device: Altice s51 with Android 7.0

I have to restart the device to the app detect the new timezone set.

This is definitely happening on my Samsung Galaxy S7 device using RN 0.55.4. It is 15 hours ahead even though I am using PST timezone.

Was this page helpful?
0 / 5 - 0 ratings