Skip to content

Commit

Permalink
Cron: Don't use a tz other than the default one
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Aug 8, 2023
1 parent 4afe82c commit 663a205
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Cron\CronExpression;
use DateTime;
use DateTimeInterface;
use DateTimeZone;
use InvalidArgumentException;
use ipl\Scheduler\Contract\Frequency;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 663a205

Please sign in to comment.