diff --git a/src/Cron.php b/src/Cron.php index 56de840..e35dc03 100644 --- a/src/Cron.php +++ b/src/Cron.php @@ -5,6 +5,7 @@ use Cron\CronExpression; use DateTime; use DateTimeInterface; +use DateTimeZone; use InvalidArgumentException; use ipl\Scheduler\Contract\Frequency; @@ -98,6 +99,9 @@ public function getExpression(): string public function startAt(DateTimeInterface $start): self { $this->start = clone $start; + // If the start time tz is somehow set to UTC (because someone didn't use our frequency format), + // but are using non UTC tz, we have to enforce to use the configured default time zone. + $this->start->setTimezone(new DateTimeZone(date_default_timezone_get())); return $this; } @@ -112,6 +116,9 @@ public function startAt(DateTimeInterface $start): self public function endAt(DateTimeInterface $end): Frequency { $this->end = clone $end; + // If the end time tz is somehow set to UTC (because someone didn't use our frequency format), + // but are using non UTC tz, we have to enforce to use the configured default time zone. + $this->end->setTimezone(new DateTimeZone(date_default_timezone_get())); return $this; }