Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob] Fix handling of timezone

Neeraj Gupta10079d4cb0ed
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<DateTime?> 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<String> 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);