From 664457b17ebdd7c4d90f706beafc865c2136cee1 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 27 Sep 2022 14:05:26 -0700 Subject: [PATCH] exif: forget time zone in fallback --- lib/Exif.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Exif.php b/lib/Exif.php index 90933da9..80d3395d 100644 --- a/lib/Exif.php +++ b/lib/Exif.php @@ -267,10 +267,28 @@ class Exif { } } + /** + * Forget the timezone for an epoch timestamp and get the same + * time epoch for UTC. + * + * @param int $epoch + */ + public static function forgetTimezone($epoch) { + $dt = new \DateTime(); + $dt->setTimestamp($epoch); + $tz = getenv('TZ'); // at least works on debian ... + if ($tz) { + $dt->setTimezone(new \DateTimeZone($tz)); + } + $utc = new \DateTime($dt->format('Y-m-d H:i:s'), new \DateTimeZone('UTC')); + return $utc->getTimestamp(); + } + /** * Get the date taken from either the file or exif data if available. * @param File $file * @param array $exif + * @return int unix timestamp */ public static function getDateTaken(File &$file, array &$exif) { $dt = $exif['DateTimeOriginal'] ?? null; @@ -290,7 +308,7 @@ class Exif { if ($dateTaken == 0) { $dateTaken = $file->getMtime(); } - return $dateTaken; + return self::forgetTimezone($dateTaken); } /**