luxon icon indicating copy to clipboard operation
luxon copied to clipboard

Luxon DateTime fromISO have wrong offset on React Native Android

Open caohaley opened this issue 2 years ago • 4 comments

Describe the bug When using Luxon's DateTime on React Native Android app vs React Native for Web, the offset from DateTime.fromISO('1953-03-21'), will be 60 minutes different on the two platforms, whereas the expected result is that they should give the same DateTime.

This results in a difference in the output dates when using date formatters like toLocaleString(DateTime.DATE_FULL) and toFormat('f) between Web and Android.

To Reproduce When printing date using Luxon DateTime on React Native Android app:

DateTime.fromISO('1953-03-21').toLocaleString(DateTime.DATE_FULL) and also: DateTime.fromISO('1953-03-21').toFormat('f)

These two will give March 20, 1953 instead of March 21, 1953 on Android app, but will be correct on web.

Actual vs Expected behavior The lines of code will give March 20, 1953 instead of March 21, 1953 on Android app, but will be correct on web. March 20th, 1953 is obviously incorrect since we passed in 1953-03-21 in ISO format.

Desktop (please complete the following information):

System: OS: macOS 11.4 CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz Memory: 1011.43 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.17.3 - /usr/local/bin/node Yarn: 1.22.17 - ~/core/www/node_modules/.bin/yarn npm: 7.21.1 - /usr/local/bin/npm Watchman: Not Found Managers: CocoaPods: Not Found SDKs: iOS SDK: Not Found Android SDK: Not Found IDEs: Android Studio: 2021.1 AI-211.7628.21.2111.8092744 Xcode: /undefined - /usr/bin/xcodebuild Languages: Java: 11.0.12 - /Users/haleycao/.jenv/shims/javac npmPackages: @react-native-community/cli: Not Found react: ^17.0.2 => 17.0.2 react-native: ^0.66.4 => 0.66.4 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

  • Luxon version 2.3.0
  • My timezone America/Los_Angeles

Additional context I am running a React Native Android app when witnessing this incorrect DateTime from ISO.

caohaley avatar Jun 06 '22 19:06 caohaley

Is there some way I can easily reproduce this without setting up a react-native app?

icambron avatar Jun 06 '22 22:06 icambron

This wrong offset is only observed on React Native for Android specifically, I think you will probably need to set up a really basic react native app to reproduce it

caohaley avatar Jun 06 '22 23:06 caohaley

The issue is that I'm not going to do that. That's why I was hoping there was, I don't know, a web page that ran an emulator and let me debug it, or some similar way you could send me a link where I could reproduce it. As in, I'd be happy to spend a bit of time sorting through what's happening there, but I'm not going to go build an app for it. I don't even have an Android phone.

But I'll leave this open in case someone else is up to the task.

icambron avatar Jun 07 '22 01:06 icambron

Sounds like a problem of Android's implementation of the date object not a problem with Luxon. Use the Platform API in react native to detect if the platform is android and them provide the 60 minute offset in your date object.

Enragedsaturday avatar Jun 28 '22 20:06 Enragedsaturday