Timezone conversion is not working properly on iOS 14
See original GitHub issuePlease provide all the information requested. Issues that do not follow this format are likely to stall.
Description
Hello Guys, I’ve noticed and I been receiving users feedbacks that all dates and other functions related to dates (like local push notifications, reminders, and others) are wrong on the latest iOS 14 on my app.
Basically, the app/system is not being able to convert the timestamp that we get from our back-end (it’s on UTC0) to the user timezone. So, for example, I’m on UTC -3 and all timestamps on the app are being presented to me 3 hours later.
The odd thing about this is that is only happening with iOS 14 users. I use the same codebase and test it out on iOS 14 devices, <= iOS 13 devices, Android Devices with different android versions, and the only one that presents the issue was the devices with the newer iOS 14.
I’ve been searching for answers or fixes related to that for the past couple of weeks and so far I wasn’t able to fix that, so at least I wanted to know if this is a React Native issue or an Apple issue or maybe both? This app is live for quite some time now and this logic as well, I really didn’t want to refactor the whole timezone logic. (and even don’t know if I can afford the time spent).
Any help would be awesome!
React Native version:
System:
OS: macOS 10.15.7
CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
Memory: 22.51 MB / 8.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.18.4
Yarn: 1.22.5
npm: 6.14.6 - /usr/local/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.9.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.1, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0
Android SDK:
API Levels: 28, 29, 30
Build Tools: 28.0.3, 29.0.2, 30.0.2
System Images: android-23 | Google APIs Intel x86 Atom, android-25 | Google Play Intel x86 Atom, android-29 | Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 4.0
Xcode: 12.1- /usr/bin/xcodebuild
Languages:
Java: 1.8.0_265 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.0 => 0.63.0
react-native-macos: Not Found
Steps To Reproduce
It’s pretty much explained in the description, I don’t believe that is a code issue, at least for now.
Expected Results
Users should be able to get the correct timestamp on their apps on the iOS14.
Snack, code example, screenshot, or link to a repository:
Issue Analytics
- State:
- Created 3 years ago
- Comments:11
@ravirajn22 Thank you so much for your help. I didn’t know about that situation with date strings and the StackOverflow link help me out to find a solution! Basically, I’m checking the date sting and adding the “Z” to the end. Now, iOS 14 is able to show and understand the right date on my app. cheers 👍
https://stackoverflow.com/a/13363791/1250311
Also read this Date.parse which it uses, https://tc39.es/ecma262/#sec-date.parse
The above links pretty clearly solves your problem and tells why iOS 14 way of handling date-time string without timezone is correct according to new es5 javascript spec matching ISO 8601.
Post here if you have any doubts.