From 9a029f7505837daf945a94f82ecdc305c89c0d58 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Thu, 27 Feb 2025 11:38:02 +0000 Subject: [PATCH] Fix entry scheduling when app timezone isn't UTC --- src/Jobs/HandleEntrySchedule.php | 3 ++- src/Query/Builder.php | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Jobs/HandleEntrySchedule.php b/src/Jobs/HandleEntrySchedule.php index 3317bd53d8..07cfea35db 100644 --- a/src/Jobs/HandleEntrySchedule.php +++ b/src/Jobs/HandleEntrySchedule.php @@ -9,6 +9,7 @@ use Illuminate\Support\Collection; use Statamic\Entries\MinuteEntries; use Statamic\Events\EntryScheduleReached; +use Statamic\Facades\Entry; class HandleEntrySchedule implements ShouldQueue { @@ -25,7 +26,7 @@ private function entries(): Collection // were scheduled for then would now be considered published. If we were targeting // the current minute and the entry has defined a time with seconds later in the // same minute, it may still be considered scheduled when it gets dispatched. - $minute = now()->subMinute(); + $minute = now('UTC')->subMinute(); return (new MinuteEntries($minute))(); } diff --git a/src/Query/Builder.php b/src/Query/Builder.php index 8098ee9740..9dfcee2b80 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -384,10 +384,10 @@ public function whereDate($column, $operator, $value = null, $boolean = 'and') } if (! ($value instanceof DateTimeInterface)) { - $value = Carbon::parse($value); + $value = Carbon::parse($value, 'UTC'); } - $value = Carbon::parse($value->format('Y-m-d')); // we only care about the date part + $value = Carbon::parse($value->format('Y-m-d'), 'UTC'); // we only care about the date part $this->wheres[] = [ 'type' => 'Date', @@ -510,10 +510,10 @@ public function whereTime($column, $operator, $value = null, $boolean = 'and') } if (! ($value instanceof DateTimeInterface)) { - $value = Carbon::parse($value); + $value = Carbon::parse($value, 'UTC'); } - $value = $value->format('H:i:s'); // we only care about the time part + $value = $value->format('H:i:s', 'UTC'); // we only care about the time part $this->wheres[] = [ 'type' => 'Time',