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

Fixed Issue #935: Unable to select a date earlier than Unix epoch whe… #938

Closed

Conversation

FiratDede
Copy link

@FiratDede FiratDede commented Nov 5, 2024

…n only a maximum date is provided on Android

Summary

The error was described in #935

This pull request solves #935 . According to old code when you provide only maximum date, it gets minimum date timestamp as 0 (which is Thursday, January 1, 1970 12:00:00 AM) . As a result when you select the date before the minimum date, it selects minimum date, I am not sure whether it is a bug because I think you shouldn't select a date before minimum date if you give a value to maximum date . However, Maybe used minimumDate value can be changed here because there is a constant which is DEFAULT_MIN_DATE timestamp equals to -2208988800001l in RNConstants.java. You can see the code below in RNConstants.java

  /**
   * Minimum date supported by {@link TimePickerDialog}, 01 Jan 1900
   */
  public static final long DEFAULT_MIN_DATE = -2208988800001l;

And this constants matches 01 Jan 1990 date. My pull request only changes minDate as 01 Jan 1900, if this minDate is not provided by the user.

Test Plan

What's required for testing (prerequisites)?

You can use your physical devices or emulators for testing.

What are the steps to reproduce (after prerequisites)?

You can use the js code below for seeing the bug. You can replace example/App.js code with the code below:

import { useState } from "react";
import DateTimePicker from "@react-native-community/datetimepicker";
import { View, Button } from "react-native";

export default function App() {
  const [show, setShow] = useState(false);
  const [value, setValue] = useState(new Date(1970, 0, 2))

  return (
    <View style={{
      flex: 1,
      padding: 42
    }}>
      <Button title="Select Date" onPress={(e) => {
        setShow(true)
      }} />

      {show && (
        <DateTimePicker
          maximumDate={new Date(2006, 0, 1)}
          minimumDate={undefined}
          value={value}
          mode={"date"}
          onChange={
            (e, selectedDate) => {
              setValue(selectedDate)
              setShow(false)
            }}
        />)}
    </View>
  );
}

Some Videos For Showing Changes

Before Changes:
https://github.com/user-attachments/assets/42a6f688-37c1-4b1d-9f17-4e84b285f35b

After Changes:
https://github.com/user-attachments/assets/673fb04f-9e8f-4f52-942e-c7af065d1d59

Compatibility

OS Implemented
iOS
Android

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I updated the typed files (TS and Flow)
  • I added a sample use of the API in the example project (example/App.js)
  • I have added automated tests, either in JS or e2e tests, as applicable

…earlier than Unix epoch when only a maximum date is provided on Android
@FiratDede FiratDede marked this pull request as ready for review November 6, 2024 15:50
@FiratDede
Copy link
Author

Actually this PR doesn't solve #935 issue completely. As a result I will close this PR.

@FiratDede FiratDede closed this Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants