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

iOS "Invalid Date" #26

Closed
anton6 opened this issue Jul 28, 2016 · 5 comments
Closed

iOS "Invalid Date" #26

anton6 opened this issue Jul 28, 2016 · 5 comments
Labels

Comments

@anton6
Copy link

anton6 commented Jul 28, 2016

Hi

I came across the following issue for react-native-datepicker.

This is how I am using datepicker component:

<DatePicker
  mode='date'
  placeholder='DD-MM-YYYY'
  format='DD-MM-YYYY'
  date={this.state.dob}
  maxDate={moment()}
  showIcon={false}
  confirmBtnText='Confirm'
  cancelBtnText='Cancel'
  onDateChange={(dob) => { this.setState({dob}) }}
/>

Initially this.state.dob is an empty string "" so that placeholder is displayed to the user.

So when I click on datepicker component I have this:
screen shot 2016-07-28 at 17 16 01

I was expecting it to default to the current date/time instead of beginning of time.

And if I click on Confirm without selecting any date I get an error "Invalid date".

On Android I do not remember seeing this behaviour.

This is how I am currently solving the problem, but not sure if this is the best solution:

getDate(date = this.props.date) {
  if (date instanceof Date) {
    return date;
  } else {
    return date ? Moment(date, this.format).toDate() : Moment().toDate();
  }
}

Any help is appreciated, thanks.

@MaxiSantos
Copy link

I'm still seeing this bug when I don't select any date on iOS. On Android is a random bug. ANy ideas?

@MaxiSantos
Copy link

ok, for my problem this was not an issue with the datepicker library but with how I was sending the date to moment. Check this: https://stackoverflow.com/questions/41874676/react-native-code-doesnt-work-without-remote-debugger-enabled

Basically I just need to send moment('my date', 'the format so moment can correclty convert my date')

@jmknoll
Copy link

jmknoll commented Nov 6, 2018

Somewhat related to this - it appears that if you have value (non-empty string) for both placeholder and date, it will render correct in the simulator, but give invalid date on an actual iOS device. Deleting the placeholder provides a workaround, although it may not be ideal for all use cases.

@WseanKiu
Copy link

WseanKiu commented Aug 1, 2019

I fixed mine like this..,
<DatePicker
...
date={this.state.dueDate instanceof Date ? this.state.dueDate : this.state.present_date}
... />

dueDate could be a string but has a value of invalid date syntax e.g. "0000-00-00" or ""

hope this helps (:

@gshoanganh
Copy link

gshoanganh commented May 11, 2023

convert string to date, you can fix:

import moment from 'moment'
..
<DatePiker 
...
date={moment(yourDate, 'YYYY-MM-DD').toDate()}
... />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants