exif: forget time zone in fallback

pull/62/head
Varun Patil 2022-09-27 14:05:26 -07:00
parent 5bdc0d9e48
commit 664457b17e
1 changed files with 19 additions and 1 deletions

View File

@ -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);
}
/**