Fixed file modified times not respecting the configured timezone

This commit is contained in:
Chris Kankiewicz
2025-03-24 08:29:45 -07:00
parent 9f4ef4f33d
commit ae17819911
2 changed files with 9 additions and 1 deletions

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace App\ViewFunctions;
use App\Config;
use DateTimeImmutable;
use DateTimeZone;
use RuntimeException;
use Symfony\Component\Finder\SplFileInfo;
@@ -26,6 +28,10 @@ class ModifiedTime extends ViewFunction
$modifiedTime = lstat($file->getPathname())['mtime'];
}
return date($this->config->get('date_format'), $modifiedTime);
$date = DateTimeImmutable::createFromTimestamp($modifiedTime)->setTimezone(
new DateTimeZone($this->config->get('timezone'))
);
return $date->format($this->config->get('date_format'));
}
}

View File

@@ -16,6 +16,8 @@ class ModifiedTimeTest extends TestCase
#[Test]
public function it_can_return_the_modified_time_for_a_file(): void
{
$this->container->set('timezone', 'UTC');
$file = $this->createMock(SplFileInfo::class);
$file->method('getMTime')->willReturn(516976496);