henninghall / react-native-date-picker

React Native Date Picker is datetime picker for Android and iOS. It includes date, time and datetime picker modes. The datepicker is customizable and is supporting different languages. It's written with native code to achieve the best possible look, feel and performance.
MIT License
2.21k stars 338 forks source link

Bug with maximumDate and datetime mode without using minimumDate #755

Open pelomedusa opened 8 months ago

pelomedusa commented 8 months ago

Describe the bug On Android, setting the mode attribute to datetime and the maximumDate to new Date("2024-12-30") , the Datepicker opens with a minimum date of June 30 2024

The bug might be related to #670 but was not fixed by #740.

Expected behavior The minimumDate attribute is not used so the date picker should open to the current date without a minimum

To Reproduce Add example code that reproduces the behavior.

import React, {useState} from 'react';
import {
    Button,
    SafeAreaView,
    StyleSheet, Text,

} from 'react-native';

import DatePicker from "react-native-date-picker";

function App(): React.JSX.Element {
  const [value, setValue] = useState(new Date());
  const [open, setOpen] = useState(false);
  const maximumDate = new Date("2024-12-30");

  return (
    <SafeAreaView>

      <Button title={'Open datepicker'} onPress={() => setOpen(true)}/>
      <Text>{maximumDate.toString()}</Text>
      <DatePicker
          modal
          date={value}
          open={open}
          mode={'datetime'}
          maximumDate={maximumDate}
          locale={'en'}
          is24hourSource={"locale"}
          firstDay={1}
          onConfirm={(date) => {
              setValue(date);
              setOpen(false);
          }}
          onCancel={() => {
              setOpen(false)
          }}
      />
    </SafeAreaView>
  );
}

export default App;

image

Smartphone (please complete the following information):

bishoymakkar commented 7 months ago

fixed in release 4.3.6

pelomedusa commented 7 months ago

@bishoymakkar unfortunately it looks like the bug is still present in 4.3.6.

bishoymakkar commented 7 months ago

fixed in release 4.3.7 confirmed

pedrolizi commented 7 months ago

At the moment with version 4.3.7 it is still present. After putting some logs on the DatePickerAndroid.js file it shows the following

Date { NaN }

I'm using the Date Picker like this:

<DatePicker
  modal
  locale={ 'es' }
  minimumDate={ new Date() }
  mode="date"
  open={ open2 }
  date={ new Date(input_date_visit) }
  onConfirm={ date => {
    setOpen2(false)
    dispatch(setDateVisit(date))
  } }
  onCancel={ () => {
    setOpen2(false)
  } }
/>

and the functions inside the DatePickerAndroid.js file that gets the error are: _date() and _minimumDate() and that's because both uses the _toIsoWithTimeZoneOffset().

I confirmed that input_date_visit it is not a null value on the logic of my component, so that's an unexpected behavior from the package to get aDate { NaN } on the function.

Hope this helps.