From 8ff83cc3d670993274eb52fbf2c5016fb5c2acd4 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Tue, 2 Dec 2025 16:58:43 +0100 Subject: [PATCH] Fix: Pass $serverTimezone to shouldRunNow() in ServerCheckJob dispatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass the server timezone parameter to shouldRunNow() call at line 127, ensuring ServerCheckJob dispatch respects the server's local timezone instead of falling back to the instance default. This aligns the behavior with other scheduled tasks in the same method: - ServerStorageCheckJob (line 137) - ServerPatchCheckJob (line 144) - Sentinel restart (line 152) All scheduled tasks in processServerTasks() now consistently use the server's configured timezone for cron evaluation. Added unit test to verify timezone-aware cron schedule evaluation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/Jobs/ServerManagerJob.php | 2 +- .../ServerManagerJobExecutionTimeTest.php | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/Jobs/ServerManagerJob.php b/app/Jobs/ServerManagerJob.php index 61266473b..87458e8f2 100644 --- a/app/Jobs/ServerManagerJob.php +++ b/app/Jobs/ServerManagerJob.php @@ -124,7 +124,7 @@ private function processServerTasks(Server $server): void if ($sentinelOutOfSync) { // Dispatch ServerCheckJob if Sentinel is out of sync - if ($this->shouldRunNow($this->checkFrequency)) { + if ($this->shouldRunNow($this->checkFrequency, $serverTimezone)) { ServerCheckJob::dispatch($server); } } diff --git a/tests/Unit/ServerManagerJobExecutionTimeTest.php b/tests/Unit/ServerManagerJobExecutionTimeTest.php index d32db6834..56a3af7d2 100644 --- a/tests/Unit/ServerManagerJobExecutionTimeTest.php +++ b/tests/Unit/ServerManagerJobExecutionTimeTest.php @@ -95,3 +95,27 @@ // The executionTime is now 1680 seconds (28 minutes) earlier than it should be! expect($executionTime->diffInSeconds(Carbon::parse('2024-12-02 12:00:00')))->toEqual(1680); }); + +it('respects server timezone when evaluating cron schedules', function () { + // This test verifies that timezone parameter affects cron evaluation + // Set a fixed test time at 23:00 UTC + Carbon::setTestNow('2024-12-02 23:00:00', 'UTC'); + + $executionTime = Carbon::now(); + $cronExpression = new \Cron\CronExpression('0 23 * * *'); // Every day at 11 PM + + // Test 1: UTC timezone at 23:00 - should match + $timeInUTC = $executionTime->copy()->setTimezone('UTC'); + expect($cronExpression->isDue($timeInUTC))->toBeTrue(); + + // Test 2: America/New_York timezone - 23:00 UTC is 18:00 EST, should not match 23:00 cron + $timeInEST = $executionTime->copy()->setTimezone('America/New_York'); + expect($cronExpression->isDue($timeInEST))->toBeFalse(); + + // Test 3: Asia/Tokyo timezone - 23:00 UTC is 08:00 JST next day, should not match 23:00 cron + $timeInJST = $executionTime->copy()->setTimezone('Asia/Tokyo'); + expect($cronExpression->isDue($timeInJST))->toBeFalse(); + + // Test 4: Verify copy() preserves the original time + expect($executionTime->toDateTimeString())->toBe('2024-12-02 23:00:00'); +});