Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Fix: Pass $serverTimezone to shouldRunNow() in ServerCheckJob dispatch

Andras Bacsai8ff83cc3d670
diff --git a/app/Jobs/ServerManagerJob.php b/app/Jobs/ServerManagerJob.php
index 61266473bb..87458e8f28 100644
--- a/app/Jobs/ServerManagerJob.php
+++ b/app/Jobs/ServerManagerJob.php
@@ -124,7 +124,7 @@ class ServerManagerJob implements ShouldQueue
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 d32db68344..56a3af7d22 100644
--- a/tests/Unit/ServerManagerJobExecutionTimeTest.php
+++ b/tests/Unit/ServerManagerJobExecutionTimeTest.php
@@ -95,3 +95,27 @@ it('demonstrates compounding bug without copy() across multiple calls', function
// 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');
+});