trentrichardson / jQuery-Timepicker-Addon

Adds a timepicker to jQueryUI Datepicker
http://trentrichardson.com/examples/timepicker/
MIT License
2.66k stars 1.05k forks source link

different time for different days of the week #637

Open aamir2007 opened 11 years ago

aamir2007 commented 11 years ago

I wanted to add different time restrictions for different days of the week. Like for sunday wanted to change hourMax value. For this I have added setter code into onSelect: event but when it executes the calender closes and changes does not apply.

Please advice.

Regards, Aamir

ericitzhak commented 10 years ago

I also think that would be a great addition

aamir2007 commented 10 years ago

I have achieved this by following code.

jQuery("#e_deliverydate").val("").datetimepicker({hourMin:10,hourMax:19,ampm: true,minDate: new Date(2013, 10, 21, 10, 06),beforeShow: maxdt,beforeShow: maxdt,dateFormat: "d MM, yy", stepMinute:15, beforeShowDay: chd, onClose:function(dateStr,inst){ var monthValue = inst.selectedMonth+1; var dayValue = inst.selectedDay; var yearValue = inst.selectedYear; var all=dayValue+"-"+monthValue+"-"+yearValue; jQuery("#h_deliverydate").val(all);},

onSelect:function(dateStr,inst){

    var selectedDate = new Date(dateStr);
    var selectedDay = selectedDate.getDay();        

// add different time settings if day is sunday. if(selectedDay == 0) { var currentHour = selectedDate.getHours(); var currentMinutes = selectedDate.getMinutes();

                if(currentHour < 10 || currentHour >19 || (currentHour == 19 && currentMinutes > 00))
                {

                    if(currentHour < 10){
                    currentdate = selectedDate.setHours("10");
                    currentdate = selectedDate.setMinutes("0");
                    }

                    else if(currentHour >19){
                    currentdate = selectedDate.setHours("19");
                    currentdate = selectedDate.setMinutes("00");
                    }

                    else if(currentHour == 19 && currentMinutes > 00)
                    currentdate = selectedDate.setMinutes("00");

                    jQuery("#e_deliverydate").datetimepicker("setDate",new Date(currentdate));

                }

            }
        }
})
.focus(function (event){
    jQuery.datepicker.afterShow(event);
});