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

Incorrect Date Returned When Setting Maximum Date #798

Closed sacim41 closed 5 months ago

sacim41 commented 5 months ago

Describe the bug When setting a maximum date and selecting a date beyond that limit, the returned value is consistently one day before the selected date. For instance, if I select April 16, 2024, the returned value is April 15, 2024.

Expected behavior I want the selected date to be returned accurately without any alterations or changes.

To Reproduce Add example code that reproduces the behavior.

export default class App extends Component {
  const onChange = (selectedDate: Date | undefined) => {
    const currentDate = selectedDate || date || new Date();
    console.log(currentDate)
    setDate(currentDate.toISOString());
  };

  render = () =>
    <DatePicker
                modal
                testID='datePicker'
                open={showDatePicker}
                date={date ? new Date(date) : new Date()}
                onConfirm={(date) => onChange(date)}
                mode='date'
                maximumDate={new Date()}
                onCancel={() => {
                  setShowDatePicker(false)
                }}
              />

}

Smartphone (please complete the following information):

henninghall commented 5 months ago

Keep the date as Date in the state, not string (isostring). See examples in readme.