Skip to content

armgit / ente

Public Imported from GitHub
0

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

Handle compact EXIF offsets

Neeraj Guptaa64edb5a1c2d
diff --git a/mobile/apps/photos/lib/utils/exif_util.dart b/mobile/apps/photos/lib/utils/exif_util.dart
index e9476bb62d..de659ae667 100644
--- a/mobile/apps/photos/lib/utils/exif_util.dart
+++ b/mobile/apps/photos/lib/utils/exif_util.dart
@@ -29,9 +29,9 @@ final _standardExifDateTimePattern = RegExp(
r'^\d{4}:(0[1-9]|1[0-2]):(0[1-9]|[12]\d|3[01]) ([01]\d|2[0-3]):([0-5]\d):([0-5]\d)$',
);
final _isoExifDateTimePattern = RegExp(
- r'^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])[T ]([01]\d|2[0-3]):([0-5]\d):([0-5]\d)([\.:]\d+)?([Zz]|[+-](?:[01]\d|2[0-3]):[0-5]\d)?$',
+ r'^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])[T ]([01]\d|2[0-3]):([0-5]\d):([0-5]\d)([\.:]\d+)?([Zz]|[+-](?:[01]\d|2[0-3]):?[0-5]\d)?$',
);
-final _offsetPattern = RegExp(r'^([Zz]|[+-](?:[01]\d|2[0-3]):[0-5]\d)$');
+final _offsetPattern = RegExp(r'^([Zz]|[+-](?:[01]\d|2[0-3]):?[0-5]\d)$');
Future<Map<String, IfdTag>> getExif(EnteFile file) async {
try {
@@ -231,10 +231,7 @@ ParsedExifDateTime _getIsoExifDateTimeInDeviceTimezone(
);
}
-String? _normalizeOffset(
- String? offsetString, {
- bool throwOnInvalid = false,
-}) {
+String? _normalizeOffset(String? offsetString, {bool throwOnInvalid = false}) {
final offset = offsetString?.trim();
if (offset == null || offset.isEmpty) {
return null;
@@ -245,7 +242,11 @@ String? _normalizeOffset(
}
return null;
}
- return offset.toUpperCase();
+ final normalizedOffset = offset.toUpperCase();
+ if (normalizedOffset == "Z" || normalizedOffset.length == 6) {
+ return normalizedOffset;
+ }
+ return "${normalizedOffset.substring(0, 3)}:${normalizedOffset.substring(3)}";
}
DateTime _parseIsoDateTimeComponents(RegExpMatch match) {
diff --git a/mobile/apps/photos/test/utils/exif_util_test.dart b/mobile/apps/photos/test/utils/exif_util_test.dart
index 51ad038f76..2e4ea04d02 100644
--- a/mobile/apps/photos/test/utils/exif_util_test.dart
+++ b/mobile/apps/photos/test/utils/exif_util_test.dart
@@ -4,10 +4,7 @@ import "package:test/test.dart";
void main() {
group("getDateTimeInDeviceTimezone", () {
test("parses standard EXIF date time", () {
- final parsed = getDateTimeInDeviceTimezone(
- "2025:01:30 08:59:50",
- null,
- );
+ final parsed = getDateTimeInDeviceTimezone("2025:01:30 08:59:50", null);
expect(parsed.dateTime, "2025-01-30T08:59:50.000");
expect(parsed.offsetTime, isNull);
@@ -30,6 +27,17 @@ void main() {
expect(parsed.time!.toUtc(), DateTime.utc(2025, 1, 30, 7, 59, 50));
});
+ test("parses standard EXIF date time with compact separate offset", () {
+ final parsed = getDateTimeInDeviceTimezone(
+ "2025:01:30 08:59:50",
+ "+0530",
+ );
+
+ expect(parsed.dateTime, "2025-01-30T08:59:50.000");
+ expect(parsed.offsetTime, "+05:30");
+ expect(parsed.time!.toUtc(), DateTime.utc(2025, 1, 30, 3, 29, 50));
+ });
+
test("parses ISO date time with numeric offset", () {
final parsed = getDateTimeInDeviceTimezone(
"2025-01-30T08:59:50+01:00",
@@ -41,6 +49,17 @@ void main() {
expect(parsed.time!.toUtc(), DateTime.utc(2025, 1, 30, 7, 59, 50));
});
+ test("parses ISO date time with compact numeric offset", () {
+ final parsed = getDateTimeInDeviceTimezone(
+ "2025-01-30T08:59:50+0530",
+ null,
+ );
+
+ expect(parsed.dateTime, "2025-01-30T08:59:50.000");
+ expect(parsed.offsetTime, "+05:30");
+ expect(parsed.time!.toUtc(), DateTime.utc(2025, 1, 30, 3, 29, 50));
+ });
+
test("parses ISO date time with half-hour numeric offset", () {
final parsed = getDateTimeInDeviceTimezone(
"2024-04-01T19:17:29+05:30",
@@ -63,22 +82,27 @@ void main() {
expect(parsed.time!.toUtc(), DateTime.utc(2025, 1, 30, 7, 59, 50));
});
- test("parses ISO date time with Z offset", () {
+ test("parses ISO date time with compact separate numeric offset", () {
final parsed = getDateTimeInDeviceTimezone(
- "2026-04-20T00:00:00Z",
- null,
+ "2025-01-30T08:59:50",
+ "+0530",
);
+ expect(parsed.dateTime, "2025-01-30T08:59:50.000");
+ expect(parsed.offsetTime, "+05:30");
+ expect(parsed.time!.toUtc(), DateTime.utc(2025, 1, 30, 3, 29, 50));
+ });
+
+ test("parses ISO date time with Z offset", () {
+ final parsed = getDateTimeInDeviceTimezone("2026-04-20T00:00:00Z", null);
+
expect(parsed.dateTime, "2026-04-20T00:00:00.000");
expect(parsed.offsetTime, "Z");
expect(parsed.time!.toUtc(), DateTime.utc(2026, 4, 20));
});
test("parses ISO date time with space separator and no offset", () {
- final parsed = getDateTimeInDeviceTimezone(
- "2025-11-12 15:12:01",
- null,
- );
+ final parsed = getDateTimeInDeviceTimezone("2025-11-12 15:12:01", null);
expect(parsed.dateTime, "2025-11-12T15:12:01.000");
expect(parsed.offsetTime, isNull);
@@ -110,61 +134,40 @@ void main() {
test("does not guess timezone abbreviations", () {
expect(
- () => getDateTimeInDeviceTimezone(
- "2024-09-07T16:29:28CDT",
- null,
- ),
+ () => getDateTimeInDeviceTimezone("2024-09-07T16:29:28CDT", null),
throwsFormatException,
);
});
test("rejects trailing data in standard EXIF date time", () {
expect(
- () => getDateTimeInDeviceTimezone(
- "2024:09:07 16:29:28CDT",
- null,
- ),
+ () => getDateTimeInDeviceTimezone("2024:09:07 16:29:28CDT", null),
throwsFormatException,
);
expect(
- () => getDateTimeInDeviceTimezone(
- "2024:09:07 16:29:28+05:30",
- null,
- ),
+ () => getDateTimeInDeviceTimezone("2024:09:07 16:29:28+05:30", null),
throwsFormatException,
);
});
test("rejects invalid ISO date time components", () {
expect(
- () => getDateTimeInDeviceTimezone(
- "2025-02-30T08:00:00Z",
- null,
- ),
+ () => getDateTimeInDeviceTimezone("2025-02-30T08:00:00Z", null),
throwsFormatException,
);
expect(
- () => getDateTimeInDeviceTimezone(
- "2025-01-30T24:00:00+01:00",
- null,
- ),
+ () => getDateTimeInDeviceTimezone("2025-01-30T24:00:00+01:00", null),
throwsFormatException,
);
expect(
- () => getDateTimeInDeviceTimezone(
- "2025-01-30T08:00:00+99:99",
- null,
- ),
+ () => getDateTimeInDeviceTimezone("2025-01-30T08:00:00+99:99", null),
throwsFormatException,
);
});
test("rejects invalid separate offset", () {
expect(
- () => getDateTimeInDeviceTimezone(
- "2025-01-30T08:59:50",
- "CDT",
- ),
+ () => getDateTimeInDeviceTimezone("2025-01-30T08:59:50", "CDT"),
throwsFormatException,
);
});