diff --git a/cli/src/Command/BaseLoop.php b/cli/src/Command/BaseLoop.php index 04c9d61..f2ad1e6 100644 --- a/cli/src/Command/BaseLoop.php +++ b/cli/src/Command/BaseLoop.php @@ -1,6 +1,7 @@ timezone = new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago'); } + protected DateTimeZone $timezone; public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int { @@ -28,7 +31,7 @@ class BaseLoop extends Console\Command\Command $this->write($output, 'Starting loop...'); while (true) { $commands = $this->scheduleService->getPending(); - $start = new DateTimeImmutable(); + $start = new DateTimeImmutable('now', $this->timezone); foreach ($commands as $command) { $this->runCommand($input, $output, $command); } @@ -40,9 +43,9 @@ class BaseLoop extends Console\Command\Command { // wait for next minute if ($start === null) { - $start = new DateTimeImmutable(); + $start = new DateTimeImmutable('now', $this->timezone); } - $nextMinute = new DateTimeImmutable($start->format('Y-m-d H:i:00')); + $nextMinute = new DateTimeImmutable($start->format('Y-m-d H:i:00'), $this->timezone); $nextMinute = $nextMinute->add(new \DateInterval('PT1M')); $diff = $nextMinute->getTimestamp() - $start->getTimestamp(); if ($diff > 0) { @@ -71,7 +74,7 @@ class BaseLoop extends Console\Command\Command } protected function write(Console\Output\OutputInterface $output, string $message): void { - $now = new DateTimeImmutable(); + $now = new DateTimeImmutable('now', $this->timezone); $output->writeln("[{$now->format('Y-m-d H:i:s e')}] {$message}"); } } diff --git a/cli/src/Command/Money/IPC.php b/cli/src/Command/Money/IPC.php index a1b8590..0856fab 100644 --- a/cli/src/Command/Money/IPC.php +++ b/cli/src/Command/Money/IPC.php @@ -3,6 +3,7 @@ namespace Incoviba\Command\Money; use DateTimeImmutable; use DateInterval; +use DateTimeZone; use Symfony\Component\Console; use Incoviba\Common\Alias\Command; @@ -15,10 +16,12 @@ class IPC extends Command public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int { $this->logger->debug("Running {$this->getName()}"); - $lastMonth = (new DateTimeImmutable())->sub(new DateInterval('P1M')); - $endLastYear = (new DateTimeImmutable())->sub(new DateInterval('P1Y')); + $timezone = new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago'); + $now = new DateTimeImmutable('now', $timezone); + $lastMonth = $now->sub(new DateInterval('P1M')); + $endLastYear = $now->sub(new DateInterval('P1Y')); $uri = '/api/money/ipc'; - $current = new DateTimeImmutable($lastMonth->format('Y-m-d')); + $current = new DateTimeImmutable($lastMonth->format('Y-m-d'), $timezone); while ($current->diff($endLastYear)->days > 30) { $data = [ 'start' => $endLastYear->format('Y-12-1'), diff --git a/cli/src/Command/Money/UF.php b/cli/src/Command/Money/UF.php index ae1d8a8..ac1df62 100644 --- a/cli/src/Command/Money/UF.php +++ b/cli/src/Command/Money/UF.php @@ -2,6 +2,7 @@ namespace Incoviba\Command\Money; use DateTimeImmutable; +use DateTimeZone; use Symfony\Component\Console; use Incoviba\Common\Alias\Command; @@ -14,7 +15,7 @@ class UF extends Command public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int { $this->logger->debug("Running {$this->getName()}"); - $now = new DateTimeImmutable(); + $now = new DateTimeImmutable('now', new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago')); $uri = '/api/money/uf'; $data = [ 'fecha' => $now->format('Y-m-d') diff --git a/cli/src/Command/Queue.php b/cli/src/Command/Queue.php index 24f5619..ddd4e5e 100644 --- a/cli/src/Command/Queue.php +++ b/cli/src/Command/Queue.php @@ -2,6 +2,7 @@ namespace Incoviba\Command; use DateTimeImmutable; +use DateTimeZone; use Psr\Http\Client\ClientInterface; use Psr\Log\LoggerInterface; use Symfony\Component\Console; @@ -24,7 +25,7 @@ class Queue extends Command { $this->logger->debug("Running {$this->getName()}"); $io = new Console\Style\SymfonyStyle($input, $output); - $now = new DateTimeImmutable(); + $now = new DateTimeImmutable('now', new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago')); $io->title("[{$now->format('Y-m-d H:i:s e')}] Running Queue..."); $jobs = $this->getJobs($output);