Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timezone issue when using polyfill #7204

Closed

Conversation

auroursa
Copy link
Contributor

Stack on #7195(commit).

According to the documentation, I imported the missing add-all-tz.js, and it should work properly again.

Checked on the Galaxy S22 and iOS simulator, the timezone in the screenshot is based on Central Time (UTC-6).

@auroursa auroursa mentioned this pull request Dec 20, 2024
@surfdude29
Copy link
Contributor

This may not be feasible, but for the en-GB locale would it be possible to still use the Lingui date formatting rather than the polyfill?

The polyfill sets the format as [date], [time] for en-GB on iOS (not sure about other platforms):
IMG_1678

Which I think doesn't look as good as Lingui displays it, as [date] at [time]:
IMG_1883

@auroursa
Copy link
Contributor Author

This may not be feasible, but for the en-GB locale would it be possible to still use the Lingui date formatting rather than the polyfill?

As mentioned here

Lingui does not format dates by itself. It internally uses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl.

If dates are not formatted correctly for you it's most likely because you need to set up the polyfill: https://lingui.dev/tutorials/react-native#polyfilling-intl-apis

Also can refer to the related discussion in #7138. After Lingui adds support for date formatting, polyfills will still need to be introduced.

After applying the polyfill, there is indeed some regression with en-GB, as you mentioned. But I believe it is still within an acceptable range compared to the issues with Chinese and Japanese (I also checked the other supported app languages, and there were no particularly severe regressions).

This does not mean en-GB has been compromised. I noticed that /@formatjs/intl-datetimeformat/locale-data/en-GB.js defines how to format date outputs. I will look for ways to improve it upstream to reach the level prior to the polyfill.

This is a improvement process, but first, let’s fix the date display for Chinese, as it currently uses the en-US date format to display post times. I’d like to hear your thoughts on this.

@auroursa
Copy link
Contributor Author

Referring to the documentation, I think I have a general understanding of why Chinese cannot display post time correctly without a polyfill.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl

"zh-Hans-CN": Chinese (language) written in simplified characters (script) as used in China (region)

Here Chinese is labeled using the RFC 4646 standard (zh-Hans-CN), but the application language currently uses RFC 1766 (zh-CN). I think that’s the root cause.

For some reason, Android only supports Intl with the RFC 4646 standard and not for RFC 1766. iOS and Web can correctly handle both RFC 4646 and RFC 1766. So, by introducing a polyfill, Android can correctly recognize zh-CN labeled with RFC 1766.

Without relying on a polyfill, post time issues on Android cannot be resolved in the short term unless we switch to a method other than Intl for formatting time.

Alternatively, we could switch the app language for Chinese to RFC 4646 to stop introducing the polyfill, but this would make handling browser compatibility more challenging, as most browsers still follow RFC 1766...

The overly chaotic standards are the biggest challenge in maintaining Chinese localization, especially for cross-platform app. I’m completely exhausted.😢

@auroursa auroursa changed the title Fix date time format localtime issue Fix timezone issue when using polyfill Dec 21, 2024
@auroursa
Copy link
Contributor Author

No longer using polyfill, fixing this issue by modifying the language codes for Chinese. #7235

@auroursa auroursa closed this Dec 23, 2024
@auroursa auroursa deleted the fix-datetimeformat-localtime branch December 23, 2024 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants