Skip to content

Commit

Permalink
Do not set timezone specifically for last modified dates
Browse files Browse the repository at this point in the history
We need timezones to be the same across all elements of the
application.

Doctrine requires the same timezone to be used when saving and loading
dates.
https://www.doctrine-project.org/projects/doctrine-orm/en/2.19/cookbook/working-with-datetime.html#default-timezone-gotcha

If timezones are different then the system will not be able to
identify a cover file as being unchanged because the modified time
might be different.

Consequently we need to avoid setting the timezone explicitly
whereever possible.
  • Loading branch information
kasperg committed Mar 5, 2024
1 parent 05b80bc commit 99292be
Showing 1 changed file with 1 addition and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,14 @@ public static function setLastModified(VendorImageItem $item, ResponseInterface
{
$headers = $response->getHeaders();

$timezone = new \DateTimeZone('UTC');
if (isset($headers['last-modified']) && !empty($headers['last-modified'])) {
$lastModified = \DateTime::createFromFormat(
'D, d M Y H:i:s \G\M\T',
array_shift($headers['last-modified']),
$timezone
);
} else {
// Not all server send last modified headers so fallback to now.
$lastModified = new \DateTime('now', $timezone);
$lastModified = new \DateTime();
}
$item->setOriginalLastModified($lastModified);
}
Expand Down

0 comments on commit 99292be

Please sign in to comment.