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

toLocaleString date function returns the wrong date for "Asia/Singapore" timezone and 1981 and older years #1485

Open
nlyzhov-spotnana opened this issue Aug 20, 2024 · 4 comments

Comments

@nlyzhov-spotnana
Copy link

nlyzhov-spotnana commented Aug 20, 2024

Description

Hello. Recently we got a bug for showing dates, where the date was shown with -1 day. During the investigation, the issue is found only in Asia/Singapore timezone and only for dates 1981 and older. The reason for this bug is that toLocaleString converts the timezone wrong, it gives 11.30 pm of the previous day instead of 12.00 am of the current day.
This bug is only on mobile, the web shows the correct date.
The date returned from (new Date('1979-01-24T00:00:00').toLocaleString() :
Web: 01/24/1979, 12:00:00 AM
Mobile: 01/23/1979, 23:30:00 PM

Steps to reproduce

  1. Install the application for iPhone or Android (reproducible on both)
  2. Use this component to reproduce:
import { StyleSheet, View, Text } from 'react-native';

const styles = StyleSheet.create({
    titleContainer: {
        marginTop: 100,
    },
});

export default function HomeScreen() {
    const currentDateString = new Date('2024-08-01T00:00:00').toString();
    const currentDateLocale = (new Date('2024-08-01T00:00:00')).toLocaleString('en-US');

    const oldDateIString = new Date('1981-01-01T00:00:00').toString();
    const oldLocale = (new Date('1981-01-01T00:00:00')).toLocaleString('en-US');

  return (
    <View style={styles.titleContainer}>
        <Text>currentDateString: {currentDateString}</Text>
        <Text>currentDateLocale: {currentDateLocale}</Text>
        <Text>----------------------</Text>
        <Text>oldDateString: {oldDateString}</Text>
        <Text>oldLocale: {oldLocale}</Text>
    </View>
  );
}
  1. Go to Mac settings and switch manually the timezone to Singapore
image
  1. Refresh the app

  2. Check the oldLocale variable in the app: it shows oldLocale: 12/31/1980, 11:30:00 PM

image

React Native Version

0.72 - 0.74

Affected Platforms

Runtime - Android, Runtime - iOS

Output of npx react-native info

System:
  OS: macOS 14.5
  CPU: (12) arm64 Apple M3 Pro
  Memory: 87.89 MB / 36.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.19.0
    path: ~/.nvm/versions/node/v18.19.0/bin/node
  Yarn:
    version: 1.22.21
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.2.3
    path: ~/.nvm/versions/node/v18.19.0/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/nlyzhov/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11330709
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 21.0.4
    path: /usr/bin/javac
  Ruby:
    version: 3.1.4
    path: /Users/nlyzhov/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.5
    wanted: 0.74.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

info React Native v0.75.1 is now available (your project is running on v0.74.5).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.75.1
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.74.5
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".

Stacktrace or Logs

No crash or failure

Reproducer

https://snack.expo.dev/pJ9xRMNJBfGg39ajN7uDv

Screenshots and Videos

image
@react-native-bot
Copy link

⚠️ Add or Reformat Version Info
ℹ️ We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.70.2

@react-native-bot
Copy link

⚠️ Add or Reformat Version Info
ℹ️ We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.70.2

@nlyzhov-spotnana nlyzhov-spotnana changed the title toLocaleString date function return wrong date for "Asia/Singapore" timezone and 1981 and older years toLocaleString date function returns the wrong date for "Asia/Singapore" timezone and 1981 and older years Aug 20, 2024
@cipolleschi
Copy link

I think this is. bug in Hermes which implements I18n.
@cortinico how can we move this to the hermes repo?

@cortinico cortinico transferred this issue from facebook/react-native Aug 20, 2024
@neildhar
Copy link
Contributor

Hey @nlyzhov-spotnana, thanks for reporting this. I can reproduce the behaviour you're seeing. The issue seems to be that the timezone in Singapore changed in 1982 from +0730 to +0800. When we initially construct the date, we use the current timezone of +0800, but when converting it back to a localised string, the Intl implementation correctly uses the older timezone of +0730.

We'll look into this.

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

No branches or pull requests

4 participants