Skip to content

Date.prototype.toLocaleDateString crashes App on Android when Date value is negative #31005

Description

@Yonom

Description

On Android devices, calling the Date.prototype.toLocaleDateString() function with a date that is earlier than 1900-01-01 crashes the app.

React Native version:

System:
OS: macOS 11.2
CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
Memory: 708.55 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.15.3 - ~/.nvm/versions/node/v14.15.3/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 7.5.3 - ~/.nvm/versions/node/v14.15.3/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.1 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
Android SDK:
API Levels: 24, 29
Build Tools: 28.0.3, 29.0.2, 30.0.2, 30.0.3
System Images: android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 4.1 AI-201.8743.12.41.6953283
Xcode: 12.4/12D4e - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_282 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: ~0.63.4 => 0.63.4
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps To Reproduce

  1. Create a new React Native 0.63.4 project
  2. Paste the following code somewhere where it's executed:
try {
  new Date('1899-12-31').toLocaleDateString('en');
} catch {}

Expected Results

The app does not crash when it is opened on Android.

Snack, code example, screenshot, or link to a repository:

https://snack.expo.io/@yonom/grumpy-cookies

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions