mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-04 03:27:09 -05:00 
			
		
		
		
	* chore: bump dart sdk to 3.8 * chore: make build * make pigeon * chore: format files --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
		
			
				
	
	
		
			31 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
import 'package:immich_mobile/entities/asset.entity.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);
 | 
						|
  }
 | 
						|
}
 |