From 10079d4cb0edcf09a829f626eb64ffe541ae272b Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 7 Feb 2025 12:35:15 +0530 Subject: [PATCH] [mob] Fix handling of timezone --- mobile/lib/utils/exif_util.dart | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/mobile/lib/utils/exif_util.dart b/mobile/lib/utils/exif_util.dart index 652336ebee..45741f07b6 100644 --- a/mobile/lib/utils/exif_util.dart +++ b/mobile/lib/utils/exif_util.dart @@ -154,24 +154,22 @@ Future getCreationTimeFromEXIF( } DateTime getDateTimeInDeviceTimezone(String exifTime, String? offsetString) { - final DateTime result = DateFormat(kExifDateTimePattern).parse(exifTime); + final shouldParseDateInUTCTimeZone = offsetString != null; + final DateTime result = DateFormat(kExifDateTimePattern) + .parse(exifTime, shouldParseDateInUTCTimeZone); if (offsetString == null) { return result; } try { final List splitHHMM = offsetString.split(":"); - // Parse the offset from the photo's time zone final int offsetHours = int.parse(splitHHMM[0]); final int offsetMinutes = int.parse(splitHHMM[1]) * (offsetHours.isNegative ? -1 : 1); // Adjust the date for the offset to get the photo's correct UTC time final photoUtcDate = result.add(Duration(hours: -offsetHours, minutes: -offsetMinutes)); - // Getting the current device's time zone offset from UTC - final now = DateTime.now(); - final localOffset = now.timeZoneOffset; - // Adjusting the photo's UTC time to the device's local time - final deviceLocalTime = photoUtcDate.add(localOffset); + // Convert the UTC time to the device's local time + final deviceLocalTime = photoUtcDate.toLocal(); return deviceLocalTime; } catch (e, s) { _logger.severe("tz offset adjust failed $offsetString", e, s);