facebook / facebook/hermes

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

Open
#1,485 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
11.3k
Forks
859
Avg merge
1h 30m
Merged PRs (30d)
3

Description

### 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 (

currentDateString: {currentDateString}
currentDateLocale: {currentDateLocale}
----------------------
oldDateString: {oldDateString}
oldLocale: {oldLocale}

);
}
```
3. Go to Mac settings and switch manually the timezone to `Singapore`

image

4. Refresh the app

6. 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`

```text
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

```text
No crash or failure
```

### Reproducer

https://snack.expo.dev/pJ9xRMNJBfGg39ajN7uDv

### Screenshots and Videos

image

Contributor guide

Open the contributing guide

Research direction

Start with the reported toLocaleString entry point and the linked Snack reproducer, using Asia/Singapore on iOS and Android with dates from 1981 and earlier. Compare the mobile output with the web result for the same dates; done means the locale conversion no longer shifts the date or time by 30 minutes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
internationalization, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.