086a957a2b
* chore: text correction * fix: update activities stat only when the widget is mounted * feat(mobile): edit date time * feat(mobile): edit location * chore(build): update gradle wrapper - 7.6.3 * style: dropdownmenu styling * style: wrap locationpicker in singlechildscrollview * test: add unit test for getTZAdjustedTimeAndOffset * pr changes --------- Co-authored-by: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
36 lines
1.2 KiB
Dart
36 lines
1.2 KiB
Dart
import 'package:immich_mobile/shared/models/asset.dart';
|
|
import 'package:timezone/timezone.dart';
|
|
|
|
extension TZExtension on Asset {
|
|
/// Returns the created time of the asset from the exif info (if available) or from
|
|
/// the fileCreatedAt field, adjusted to the timezone value from the exif info along with
|
|
/// the timezone offset in [Duration]
|
|
(DateTime, Duration) getTZAdjustedTimeAndOffset() {
|
|
DateTime dt = fileCreatedAt.toLocal();
|
|
if (exifInfo?.dateTimeOriginal != null) {
|
|
dt = exifInfo!.dateTimeOriginal!;
|
|
if (exifInfo?.timeZone != null) {
|
|
dt = dt.toUtc();
|
|
try {
|
|
final location = getLocation(exifInfo!.timeZone!);
|
|
dt = TZDateTime.from(dt, location);
|
|
} on LocationNotFoundException {
|
|
RegExp re = RegExp(
|
|
r'^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$',
|
|
caseSensitive: false,
|
|
);
|
|
final m = re.firstMatch(exifInfo!.timeZone!);
|
|
if (m != null) {
|
|
final duration = Duration(
|
|
hours: int.parse(m.group(1) ?? '0'),
|
|
minutes: int.parse(m.group(2) ?? '0'),
|
|
);
|
|
dt = dt.add(duration);
|
|
return (dt, duration);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return (dt, dt.timeZoneOffset);
|
|
}
|
|
}
|