碳:计划后增加60秒间隔

时间:2018-12-19 10:18:42

标签: laravel laravel-5.4

如何在我的代码中插入addSeconds函数?我想发生的是比赛将在日程表后1分钟开始。例如,时间表是在3:00,它将从3:01开始。这是代码:

public function handle()
{
    $matches = \App\Match::where('status', 'open')->get();
    foreach($matches as $match) {
        if($match->teamA->name == 'TBD' || $match->teamB->name == 'TBD') {
            continue;
        }
        if(\Carbon\Carbon::now()->addSeconds(60)->diffForHumans()->diffInSeconds($match->schedule, false) <= 0 && !$match->re_opened) {
            $this->info('[' . \Carbon\Carbon::now() . '] Found match [Match ID: ' . $match->id . '] ' . $match->name . ' - closing...');
            setupOngoingMatch($match);
        }
    }
}

但是没有用。有任何想法吗? TYIA

1 个答案:

答案 0 :(得分:0)

If the schedule returns a Carbon object, you can simply do the following

if($match->schedule->diffInSeconds(\Carbon::now()->addSeconds(60)) => 0 && !$match->re_opened) {
    setupOngoingMatch($match);
}

If not just do the following

if(\Carbon::now()->addSeconds(60)->diffInSeconds($match->schedule) => 0 && !$match->re_opened) {
    setupOngoingMatch($match);
}