longbill / jquery-date-range-picker

A jQuery plugin that allows user to select a date range
MIT License
1.12k stars 578 forks source link

why isValidTime check all days between start day and evaluating date? #302

Open riccardonar opened 7 years ago

riccardonar commented 7 years ago

Your demo Typical usage, hotel booking not work well after you choose a day.

In your code isValidTime check all days between start day and evaluating day and i don't understand why.

For me the right code would be:

function isValidTime(time)
{
    time = parseInt(time, 10);
    if (opt.startDate && compare_day(time, opt.startDate) < 0) return false;
    if (opt.endDate && compare_day(time, opt.endDate) > 0) return false;

    if (opt.start && !opt.end && !opt.singleDate)
    {
        //check maxDays and minDays setting
        if (opt.maxDays > 0 && countDays(time, opt.start) > opt.maxDays) return false;
        if (opt.minDays > 0 && countDays(time, opt.start) < opt.minDays) return false;

        //check selectForward and selectBackward
        if (opt.selectForward && time < opt.start ) return false;
        if (opt.selectBackward && time > opt.start) return false;

        //check disabled days
        if (opt.beforeShowDay && typeof opt.beforeShowDay == 'function')
        {
            var arr = opt.beforeShowDay( new Date(time) );
            return arr[0];
        }
    }
    return true;
}
riccardonar commented 7 years ago

Now i have understand your idea! You mean that a disable day is a sold out day, so a range throught this day isn't bookable.

And if i want limit the arrival only on Saturday, how i can do? Perhaps you can add start day to beforeShowDay function or for compatibilty add another option to cover my case