From 7b027a1fe9d7ea8ae611be6363ca84986bd972af Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sat, 27 May 2023 17:10:20 -0700 Subject: [PATCH] metadata: fix display of mtime (fix #666) Signed-off-by: Varun Patil --- lib/Exif.php | 15 ++++++++------- src/components/Metadata.vue | 8 +++++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/Exif.php b/lib/Exif.php index 705b9779..c1189861 100644 --- a/lib/Exif.php +++ b/lib/Exif.php @@ -202,14 +202,15 @@ class Exif } // Fall back to modification time - try { - $parseTz = new \DateTimeZone(getenv('TZ')); // debian - } catch (\Error $e) { - $parseTz = new \DateTimeZone('UTC'); - } + $dt = new \DateTime('@'.$file->getMtime()); - $dt = new \DateTime('@'.$file->getMtime(), $parseTz); - $dt->setTimezone($parseTz); + // Set timezone to system timezone + $tz = getenv('TZ') ?: date_default_timezone_get(); + try { + $dt->setTimezone(new \DateTimeZone($tz)); + } catch (\Exception $e) { + throw new \Error("FATAL: system timezone is invalid (TZ): $tz"); + } return self::forgetTimezone($dt); } diff --git a/src/components/Metadata.vue b/src/components/Metadata.vue index 0993c352..29bcd829 100644 --- a/src/components/Metadata.vue +++ b/src/components/Metadata.vue @@ -179,8 +179,14 @@ export default defineComponent({ let dateWithTz: DateTime | undefined = undefined; + // If no timezone info is available, we will show the local time only + // In this case, everything happens in UTC + if (!tzOffset && !tzId) { + dateWithTz = date.setZone('UTC'); + } + // Use timezone offset if available - if (tzOffset) { + if (!dateWithTz?.isValid && tzOffset) { dateWithTz = date.setZone('UTC' + tzOffset); }