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

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

Open
2 tasks done
tom-un opened this issue Nov 26, 2024 · 1 comment
Open
2 tasks done

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

tom-un opened this issue Nov 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@tom-un
Copy link

tom-un commented Nov 26, 2024

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.

@tom-un tom-un added the bug Something isn't working label Nov 26, 2024
@AndrewBarzu
Copy link

This starts happening whenever the year is before 1582, possibly because of this:
https://en.wikipedia.org/wiki/1582

Seems like leap years are also possibly not counted correctly before 1582, as the days start shifting with every 100 years we go back from 1582. (except on 1100, 700, 300)

@tom-un tom-un changed the title Date.toLocaleString() is off by 2 days for old dates. Date.toLocaleString() is off by 2 days for dates before 1582. Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants