mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-16 11:04:03 +02:00
Fixed file modified times not respecting the configured timezone
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user