From 07033bdf787ae46e22860d2d04a1f30d283d472c Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Wed, 12 Jul 2023 11:16:12 +1000 Subject: [PATCH] Display next due time correctly for sub-minute events --- .../Scheduling/ScheduleListCommand.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php index 6a1128827183..a3556e35a13d 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php @@ -164,11 +164,31 @@ private function sortEvents(\Illuminate\Support\Collection $events, DateTimeZone */ private function getNextDueDateForEvent($event, DateTimeZone $timezone) { - return Carbon::instance( + $nextDueDate = Carbon::instance( (new CronExpression($event->expression)) ->getNextRunDate(Carbon::now()->setTimezone($event->timezone)) ->setTimezone($timezone) ); + + if (! $event->isRepeatable()) { + return $nextDueDate; + } + + $previousDueDate = Carbon::instance( + (new CronExpression($event->expression)) + ->getPreviousRunDate(Carbon::now()->setTimezone($event->timezone), allowCurrentDate: true) + ->setTimezone($timezone) + ); + + $now = Carbon::now()->setTimezone($event->timezone); + + if (! $now->copy()->startOfMinute()->eq($previousDueDate)) { + return $nextDueDate; + } + + return $now + ->endOfSecond() + ->ceilSeconds($event->repeatSeconds); } /**