From bcb3f5d5fae7b566fded8dc7d0bf085e6b4cfbf3 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 31 Aug 2018 21:12:10 -0700 Subject: [PATCH] Fix handling of times --- app/Services/Schedules/ProcessScheduleService.php | 9 +++++---- .../Services/Schedules/ProcessScheduleServiceTest.php | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Services/Schedules/ProcessScheduleService.php b/app/Services/Schedules/ProcessScheduleService.php index 8c157e39e..c83ad5104 100644 --- a/app/Services/Schedules/ProcessScheduleService.php +++ b/app/Services/Schedules/ProcessScheduleService.php @@ -6,6 +6,7 @@ use DateTimeInterface; use Cron\CronExpression; use Cake\Chronos\Chronos; use Pterodactyl\Models\Schedule; +use Cake\Chronos\ChronosInterface; use Pterodactyl\Services\Schedules\Tasks\RunTaskService; use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface; @@ -84,14 +85,14 @@ class ProcessScheduleService * Get the timestamp to store in the database as the next_run time for a schedule. * * @param string $formatted - * @return string + * @return \Cake\Chronos\ChronosInterface */ - private function getRunAtTime(string $formatted) + private function getRunAtTime(string $formatted): ChronosInterface { if (! is_null($this->runTimeOverride)) { - return $this->runTimeOverride->format(Chronos::ATOM); + return $this->runTimeOverride instanceof ChronosInterface ? $this->runTimeOverride : Chronos::instance($this->runTimeOverride); } - return CronExpression::factory($formatted)->getNextRunDate()->format(Chronos::ATOM); + return Chronos::instance(CronExpression::factory($formatted)->getNextRunDate()); } } diff --git a/tests/Unit/Services/Schedules/ProcessScheduleServiceTest.php b/tests/Unit/Services/Schedules/ProcessScheduleServiceTest.php index 92f7c3960..5f35187da 100644 --- a/tests/Unit/Services/Schedules/ProcessScheduleServiceTest.php +++ b/tests/Unit/Services/Schedules/ProcessScheduleServiceTest.php @@ -64,7 +64,7 @@ class ProcessScheduleServiceTest extends TestCase $formatted = sprintf('%s %s %s * %s', $model->cron_minute, $model->cron_hour, $model->cron_day_of_month, $model->cron_day_of_week); $this->repository->shouldReceive('update')->with($model->id, [ 'is_processing' => true, - 'next_run_at' => CronExpression::factory($formatted)->getNextRunDate()->format(Chronos::ATOM), + 'next_run_at' => Chronos::parse(CronExpression::factory($formatted)->getNextRunDate()->format(Chronos::ATOM)), ]); $this->runnerService->shouldReceive('handle')->with($task)->once()->andReturnNull(); @@ -84,7 +84,7 @@ class ProcessScheduleServiceTest extends TestCase $this->repository->shouldReceive('update')->with($model->id, [ 'is_processing' => true, - 'next_run_at' => Chronos::now()->addSeconds(15)->toAtomString(), + 'next_run_at' => Chronos::now()->addSeconds(15), ]); $this->runnerService->shouldReceive('handle')->with($task)->once()->andReturnNull();