首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果在指定的时间之后添加另一天的交付php

如果在指定的时间之后添加另一天的交付php
EN

Stack Overflow用户
提问于 2012-05-10 03:55:33
回答 1查看 262关注 0票数 0

我试图完成的事情是我们每周二和周四送货,我想限制如果订单是在周一下午5点以后下的,那么他们必须等到周五。如果订单是在周四下午5点以后,他们必须等到周二。

代码语言:javascript
复制
function freeDelivery($date){
    $holidays = array("05/30/2012","07/04/2012","09/05/2012","11/24/2012","11/25/2012","12/25/2012","12/31/2012","01/01/2013","05/28/2013","07/04/2013","09/03/2013","11/22/2013","11/23/2013","12/25/2013");
    $checkday = strtotime($date);
    // check if it's a holiday
    while(in_array(date("m/d/Y",$checkday), $holidays)) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 day");
    }

    //sun
    if (date("w",$checkday) == 0) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +2 day");
    }
    //mon
    elseif (date("w",$checkday) == 1) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 days");
    }
    //tue
    elseif(date("w",$checkday) == 2) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +2 days");
    }
    //wen
    elseif (date("w",$checkday) == 3) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 days");
    }
    //thur
    elseif (date("w",$checkday) == 4) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +5 days");
    }
    //fri
    elseif (date("w",$checkday) == 5) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +4 days");
    }
    //sat
    elseif (date("w",$checkday) == 6) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +3 days");
    }

    // make sure it's not another holiday
    while(in_array(date("m/d/Y",$checkday), $holidays)) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 day");
    }
    return $checkday;
}

上面的代码用于根据一周内的日期确定发货日期。

谢谢您的帮助,非常感谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-10 04:27:19

假设你的意思是周一下午5点之后是星期四,然后在星期三上下午5点之后你的意思是Tuesday...try如下:

编辑最简单的方法就是将你的代码重新添加到函数中。

代码语言:javascript
复制
function freeDelivery($date){
    $holidays = array("05/30/2012","07/04/2012","09/05/2012","11/24/2012","11/25/2012","12/25/2012","12/31/2012","01/01/2013","05/28/2013","07/04/2013","09/03/2013","11/22/2013","11/23/2013","12/25/2013");
    $checkday = strtotime($date);
    // check if it's a holiday
    while(in_array(date("m/d/Y",$checkday), $holidays)) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 day");
    }

    $thedate = date("m/d/Y",$checkday);
    $dayofweek = date("w",$checkday);
    $dayincrease = array(0 => 2, 1 => 1, 2 => 2, 3 => 1, 4 => 5, 5 => 4, 6 => 3);
    $after5 = (date("G",$checkday) >= 17);

    $increase = "";
    if($after5 && $dayofweek == 1) {
        // monday after 5p = thurs
        $increase = "+3 days";
    } elseif($after5 && $dayofweek == 3) {
        // wednesday after 5p = tues
        $increase = "+6 days";
    } else {
        $increase = "+" . $dayincrease[$dayofweek] . " days";
    }
    $checkday = strtotime($thedate." ".$increase);

    // make sure it's not another holiday
    while(in_array(date("m/d/Y",$checkday), $holidays)) {
        $checkday = strtotime(date("m/d/Y",$checkday)." +1 day");
    }
    return $checkday;
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10523185

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档