预约时间

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>营业时间</title>
</head>
<body>
    <script>    
    function timeList(startHour,startMin,startSec,endHour,endMin,endSec,delay){
        var t=new Date();
        var hour=t.getHours();//时
        var min=t.getMinutes();//分
        var sec=t.getSeconds();//秒
        var time=[];
        var h;
        var m;
        var isopen=isOpen();
        console.log("isopen");
        console.log(isopen);
        if(isopen==false){
            min=Number(startMin)+delay;
            hour=startHour;
            changeMin(hour,min,time);
            // 计算前段
            if(min!=0){
                hour=calculatebegin(hour,min,time);
            }
            // 计算中段
            calculatemiddle(hour,endHour,time);
            if(endMin!=0){
                calculateend(endHour,endMin,time);
            }
        }
        else{
            var r=min%10;
            h=hour;
            m=min-r;
            if(r==0){
                m=m+delay;
            }
            else if(r<=5){
                m=m+delay+5;
            }
            else{
                m=m+delay+10;
            }
            if(m>=60){
                m=m-60;
                h=h+1;
                time.push(h+":"+m);    
            }
            else{
                time.push(h+":"+m);
            }
            // 计算前段
            if(m!=0){
                h=calculatebegin(h,m,time);
            }
            // 计算中段
            calculatemiddle(h,endHour,time);
            if(endMin!=0){
                calculateend(endHour,endMin,time);
            }
        }
        console.log(time);
        function toDouble(num){
            if(num<10){
                return "0"+num;
            }
            else{
                return num;
            }
        }
        function calculatebegin(h,m,time){
            for(;m<60;){
                m+=5;
                if(m==60){
                    h=h+1;
                    time.push(h+":00");
                    break;
                }
                else{
                    time.push(h+":"+m);
                }
            }
            return h;
        }
        function calculatemiddle(h,endHour,time){
            for(;h<endHour;h++){
                for(var i=0;i<=55;){
                    i=i+5;
                    if(i==60){
                        time.push(h+1+":00");
                        continue;
                    }
                    else{
                        time.push(h+":"+toDouble(i));
                    }
                
                }
            }
        }
        function calculateend(endHour,endMin,time){
            for(var i=0;i<endMin;){
                i=i+5;
                time.push(endHour+":"+toDouble(i));
            }
        }
        function isOpen(){
            if(hour>startHour){
                return true;
            }
            else if(hour==startHour){
                if(min>startMin){
                    return true;
                }
                else if(min==startMin){
                    if(sec>=startSec){
                        return true;
                    }
                    else{
                        return false
                    }
                }
                else{
                    return false;
                }
            }
            else{
                return false;
            }
        }
    }
    timeList(9,40,00,13,15,00,20);        
</script>

</body>
</html>

猜你喜欢

转载自blog.csdn.net/woniudelvtu/article/details/85231452