question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[IOS] When setting minimumDate to new Date() the picker doesn't show correct initial value and set always new Date()

See original GitHub issue

Bug

Environment info

react-native info output:

"react-native": "0.61.5"
"@react-native-community/datetimepicker": "^2.2.3",

Describe what you expected to happen:

  1. I expect to init the picker with this.state.date
  2. Instead it initialize with new Date()

Reproducible sample code

<DateTimePicker
       style={{width:'100%', backgroundColor: 'white', position: 'absolute', bottom: 0, zIndex: 10}}
       value={this.state.date}
       mode={this.state.mode}
       is24Hour={true}
       onChange={this.onChangePicker}
       minimumDate={new Date()}
/>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bigescaladecommented, Sep 23, 2020

Having the same issue:

maxDate = 2020-01-31T00:00:00  
minDate = 2020-01-01T00:00:00

  <DateTimePickerModal
      isVisible={visible}
      maximumDate={maxDate}
      minimumDate={minDate}
      mode={dateOnly ? 'date' : 'datetime'}
      onCancel={() => setVisible(false)}
      onConfirm={(date) => {
        setVisible(false)
        onChange(name, date.toISOString())
      }}
    />

In this case, the date picker opens up to 31 Jan 2020, pressing the confirm button sets the date to todays date rather than 31 Jan 2020. Works fine on Android

1reaction
shinigami3000commented, Mar 26, 2020

+1 i had initialised my datePicker with new Date() but provided the maximum date of 14 years back. the picker shows the correct date but when i select the date it returns new Date(). i guess onChange is not getting called with the maximum date

Read more comments on GitHub >

github_iconTop Results From Across the Web

[IOS] When setting minimumDate to new Date() the picker ...
[IOS] When setting minimumDate to new Date() the picker doesn't show correct initial value and set always new Date() #139.
Read more >
Minimum and maximum date in UIDatePicker - Stack Overflow
datePicker.minimumDate = MinDate; // self.datePicker.maximumDate = MaxDate;. but I cant get this integer to my date format.
Read more >
<input type="date"> - HTML: HyperText Markup Language
You can set a default value for the input with a date inside the value ... the available dates (see Setting maximum and...
Read more >
Demystifying DateTime Manipulation in JavaScript - Toptal
If you instead want to get the current time stamp, you can create a new Date object and use the getTime() method. const...
Read more >
Datepicker documentation for React | Mobiscroll
Name Type Default value anchor HTMLElement undefined animation String, Boolean undefined buttons Array
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found