facebook / facebook/hermes

Date.toLocaleString() is off by 2 days for dates before 1582.

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

Description

## Bug Description
For very old dates, such as "0004-04-13T00:00:00Z", the .toLocaleString() will make the date string off by two days. i.e. it will be April 15 instead of April 13.

- [x] I have run `gradle clean` and confirmed this bug does not occur with JSC
- [x] The issue is reproducible with the latest version of React Native.

Hermes git revision (if applicable):
React Native version: 0.76
OS: iOS and Android
Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): all

## Steps To Reproduce

Go to https://reactnative.dev/docs/tutorial.

Paste the following:
```ts
import React from 'react';
import {Text, View} from 'react-native';

const HelloWorldApp = () => {
const isoDate = "0004-04-13T00:00:00Z";
const date = new Date(isoDate);
let formatOptions: Intl.DateTimeFormatOptions = {
month: "numeric",
day: "numeric",
};
const dateString = date.toLocaleString("en-US", formatOptions);
return (

{dateString}

);
};
export default HelloWorldApp;
```
Switch to Android or iOS.

## The Expected Behavior
Date should be 4/13.
Instead its 4/15.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.