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

isValidDate should handle time as well

Open Youpinadi opened this issue 10 years ago • 8 comments

futureDate(current) {
    let today = moment();
    return current.isAfter(today)
}

if i use this function as a validator, it will blur today's day, but it shouldn't. The day should be available and only hours ans minutes in the future should be available

Youpinadi avatar Sep 03 '15 15:09 Youpinadi

:+1: I've run across this issue as well. Currently we have to implement custom logic to manage time validity. Implementing an isTimeValid prop would be excellent.

iansinnott avatar Sep 22 '15 17:09 iansinnott

Sorry I could not answer this before.

It is a hard issue this one, because the UI of the datepicker makes difficult to select the valid time.

Imagine you set a function that only allow hours from 6 to 8 and 10 to 12. Pressing up and down wouldn't work ok.

That's why when a date is valid you can select any time.

If you have a solution or idea to handle this valid time issue, just leave it here.

arqex avatar Oct 01 '15 15:10 arqex

just don't handle multiple time intervals, the most common case is just to enable timepicking after a specific datetime ;)

Youpinadi avatar Oct 01 '15 16:10 Youpinadi

Why not show timepicker as a drop down list?

blackChef avatar Jul 18 '16 04:07 blackChef

@simeg are the team working on a solution for this? like a isTimeValid ? because the timeConstraints I cannot have a specific time limit like 11:25 and allowing 10:26, setting a max hour for 11 and minutes for 25, i will not be able to set 10:26, would be limited to 10:25. Am i wrong?

tunessofia avatar Sep 13 '16 17:09 tunessofia

@tunessofia from what I know no one is working on this. Your description is of timeConstraints is correct.

If we would implement a isValidTime as @Youpinadi suggests (don't handle multiple time intervals), we wouldn't have to care about the UI stuff @arqex mentions.

If people instead want to be able to control specific time intervals for specific days it becomes a bit trickier.

simeg avatar Sep 14 '16 12:09 simeg

I have seen time-pickers that works like this: unbenannt

You would not have the problem with illegal ranges becaus you can scroll over them.

Never the less i'd love to see a isValidTime- Funktion for determining a valid start-time for the picker as @tunessofia explained.

phuhl avatar Oct 21 '16 11:10 phuhl

@Youpinadi use isSameOrAfter to allow today date. The second argument should be day(string).

Like this: current.isSameOrAfter(new Date(), "day");

Manish-938 avatar Jan 25 '24 06:01 Manish-938