diff --git a/Task/Schedule.php b/Task/Schedule.php index ec299f7..6263400 100644 --- a/Task/Schedule.php +++ b/Task/Schedule.php @@ -161,6 +161,14 @@ public function setPart(int $position, string $value): self */ public function isDue($currentTime = 'now'): bool { + if (is_string($currentTime)) { + trigger_deprecation( + 'rewieer/taskschedulerbundle', + '0.12', + 'Calling isDue() with a string is deprecated, use a DateTimeInteface instance instead' + ); + } + return $this->cron->isDue($currentTime); } } diff --git a/Task/Scheduler.php b/Task/Scheduler.php index d5968c0..eaebb14 100644 --- a/Task/Scheduler.php +++ b/Task/Scheduler.php @@ -10,6 +10,7 @@ namespace Rewieer\TaskSchedulerBundle\Task; +use DateTime; use Rewieer\TaskSchedulerBundle\Event\EventDispatcher; class Scheduler @@ -39,6 +40,10 @@ public function run($currentTime = 'now'): void { $this->dispatcher->dispatch(SchedulerEvents::ON_START); + if (is_string($currentTime)) { + $currentTime = new DateTime($currentTime); + } + foreach ($this->tasks as $task) { if ($task->isDue($currentTime)) { $this->runTask($task); diff --git a/composer.json b/composer.json index a76ce53..3063eb9 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "keywords": ["cron", "task", "scheduler", "symfony", "bundle"], "require": { "php": "^7.4|^8.1", + "symfony/deprecation-contracts": "^2.5|^3.4", "symfony/framework-bundle": "^5.4|^6.4|^7.0", "symfony/console": "^5.3|^6.4|^7.0", "dragonmantank/cron-expression": "^3.3"