Skip to content

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

Open
@tom-un

Description

@tom-un

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.

  • I have run gradle clean and confirmed this bug does not occur with JSC
  • 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:

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 (
    <View
      style={{
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
      }}>
      <Text>{dateString}</Text>
    </View>
  );
};
export default HelloWorldApp;

Switch to Android or iOS.

The Expected Behavior

Date should be 4/13.
Instead its 4/15.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions