Php 使用Nesbot Carbon返回到达日期对象,以计算营业时间

Php 使用Nesbot Carbon返回到达日期对象,以计算营业时间,php,datetime,php-carbon,Php,Datetime,Php Carbon,我试图使用并返回基于当前日期时间的预期到达日期时间对象。而且还要考虑营业时间 我有一个整数值$days,我正在将其添加到当前日期时间 <?php /** * @param int $days // example defaulted to 1 day * @return object */ public static function expected_delivery_date($days = 1) { // the current date time $tim

我试图使用并返回基于当前日期时间的预期到达日期时间对象。而且还要考虑营业时间

我有一个整数值
$days
,我正在将其添加到当前日期时间

<?php

/**
 * @param int $days // example defaulted to 1 day
 * @return object
 */
public static function expected_delivery_date($days = 1)
{

    // the current date time
    $time = Carbon::now(get_option('timezone_string'))->addBusinessDays($transit);

    // return delivery date object
    return $time;

}
问题是,即使我在
Shop()
php类中定义了我的工作时间

当使用碳链功能时,
->addBusinessDays($days)
(),今天(现在的时间)是Sunday,这意味着它应该增加2天,因为今天没有营业

当前
预期交货日期()
返回明天的日期(周一)。预期结果应返回周二日期,占
营业时间
营业时间



任何关于如何在Carbon DateTime对象中添加天数并计算关闭的工作时间的想法都将非常棒,非常感谢。
addBusinessDays
不考虑开放时间

但由于您有固定的天数,因此可以使用addOpenMinutes($days*(8*60+30))

当想要添加天数时,它将取决于您的输入和业务规则,因为碳实例处理日期和时间。那么,从周日00:00或周日23:59开始的业务逻辑是否相同,返回日期的预期时间是多少。没有开放时间的任何一天是否算作0,其他所有的一天(无论开放时间是1分钟还是一整天)是否算作1

<?php

use Carbon\Carbon;
use Cmixin\BusinessTime;

class Shop
{

    public function __construct()
    {

        BusinessTime::enable(Carbon::class,[
            'monday' => ['09:00-17:30'],
            'tuesday' => ['09:00-17:30'],
            'wednesday' => ['09:00-17:30'],
            'thursday' => ['09:00-17:30'],
            'friday' => ['09:00-17:30'],
            'saturday' => [],
            'sunday' => [],
            'exceptions' => [],
            'holidaysAreClosed' => true,
            'holidays' => []
        ]);

        Carbon::setHolidaysRegion('gb-national');

    }

}

new Shop();