react-datetime icon indicating copy to clipboard operation
react-datetime copied to clipboard

How to set isValidTime?

Open wei-shuen opened this issue 7 years ago • 4 comments

Hello, first of all, I am really love this one.!!!! After I read the document file, I know I can set isVaildDate, but how to set isVaildTime?

Because now I am implementing booking meeting function, it needs to make sure that the time that user selects is not the past.

Thank you so much

wei-shuen avatar Oct 01 '18 06:10 wei-shuen

Would love an answer to this as well! It's easy to prevent a user from picking a past date, but I can't figure out how to prevent them from picking a past time. (For instance, today three hours ago).

madCode avatar Oct 15 '18 20:10 madCode

I made temporary workaround for that. In my case, I'm validating if start time- selected by a user - is before end date and is not in the past:

handleStartDateChange = () => {
  const isValid = this.isStartDateValid(start);
  if (isValid) {
    this.setState({ start });
  }
}
isStartDateValid = (curren) => {
  const min = moment();
  const end = this.state.end;
  return (current.isSame(start) || current.isAfter(start)) && (current.isSame(end) || current.isBefore(end));
};
render() {
  return (
    <DateTimePicker
      value={this.state.start}
      dateFormat="MM.DD.YYYY"
      timeFormat="HH:mm"
      onChange={this.handleStartDateChange}
      isValidDate={this.isStartDateValid}
    />
  )
}

It just validates date twice. User can still switch between hours, minutes, but time is not set. Hope it helped somehow.

c0dester avatar Feb 22 '19 09:02 c0dester

Any update on this?

KaushikTatvasoft avatar Dec 27 '23 06:12 KaushikTatvasoft

@madCode exactly what I'm looking for today. Is this possible to accomplish? Any update?

miljkovicjovan avatar Mar 08 '24 11:03 miljkovicjovan