Skip to content

Commit bcb3f5d

Browse files
committed
Fix handling of times
1 parent 178b8f8 commit bcb3f5d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

app/Services/Schedules/ProcessScheduleService.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Cron\CronExpression;
77
use Cake\Chronos\Chronos;
88
use Pterodactyl\Models\Schedule;
9+
use Cake\Chronos\ChronosInterface;
910
use Pterodactyl\Services\Schedules\Tasks\RunTaskService;
1011
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
1112

@@ -84,14 +85,14 @@ public function handle(Schedule $schedule)
8485
* Get the timestamp to store in the database as the next_run time for a schedule.
8586
*
8687
* @param string $formatted
87-
* @return string
88+
* @return \Cake\Chronos\ChronosInterface
8889
*/
89-
private function getRunAtTime(string $formatted)
90+
private function getRunAtTime(string $formatted): ChronosInterface
9091
{
9192
if (! is_null($this->runTimeOverride)) {
92-
return $this->runTimeOverride->format(Chronos::ATOM);
93+
return $this->runTimeOverride instanceof ChronosInterface ? $this->runTimeOverride : Chronos::instance($this->runTimeOverride);
9394
}
9495

95-
return CronExpression::factory($formatted)->getNextRunDate()->format(Chronos::ATOM);
96+
return Chronos::instance(CronExpression::factory($formatted)->getNextRunDate());
9697
}
9798
}

tests/Unit/Services/Schedules/ProcessScheduleServiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testScheduleIsUpdatedAndRun()
6464
$formatted = sprintf('%s %s %s * %s', $model->cron_minute, $model->cron_hour, $model->cron_day_of_month, $model->cron_day_of_week);
6565
$this->repository->shouldReceive('update')->with($model->id, [
6666
'is_processing' => true,
67-
'next_run_at' => CronExpression::factory($formatted)->getNextRunDate()->format(Chronos::ATOM),
67+
'next_run_at' => Chronos::parse(CronExpression::factory($formatted)->getNextRunDate()->format(Chronos::ATOM)),
6868
]);
6969

7070
$this->runnerService->shouldReceive('handle')->with($task)->once()->andReturnNull();
@@ -84,7 +84,7 @@ public function testScheduleRunTimeCanBeOverridden()
8484

8585
$this->repository->shouldReceive('update')->with($model->id, [
8686
'is_processing' => true,
87-
'next_run_at' => Chronos::now()->addSeconds(15)->toAtomString(),
87+
'next_run_at' => Chronos::now()->addSeconds(15),
8888
]);
8989

9090
$this->runnerService->shouldReceive('handle')->with($task)->once()->andReturnNull();

0 commit comments

Comments
 (0)