@@ -450,14 +450,14 @@ export class MetadataService extends BaseService {
450
450
}
451
451
} else {
452
452
const motionAssetId = this . cryptoRepository . randomUUID ( ) ;
453
- const createdAt = asset . fileCreatedAt ?? asset . createdAt ;
453
+ const dates = this . getDates ( asset , tags ) ;
454
454
motionAsset = await this . assetRepository . create ( {
455
455
id : motionAssetId ,
456
456
libraryId : asset . libraryId ,
457
457
type : AssetType . VIDEO ,
458
- fileCreatedAt : createdAt ,
458
+ fileCreatedAt : dates . dateTimeOriginal ,
459
459
fileModifiedAt : asset . fileModifiedAt ,
460
- localDateTime : createdAt ,
460
+ localDateTime : dates . localDateTime ,
461
461
checksum,
462
462
ownerId : asset . ownerId ,
463
463
originalPath : StorageCore . getAndroidMotionPath ( asset , motionAssetId ) ,
@@ -589,9 +589,18 @@ export class MetadataService extends BaseService {
589
589
let dateTimeOriginal = dateTime ?. toDate ( ) ;
590
590
let localDateTime = dateTime ?. toDateTime ( ) . setZone ( 'UTC' , { keepLocalTime : true } ) . toJSDate ( ) ;
591
591
if ( ! localDateTime || ! dateTimeOriginal ) {
592
- this . logger . warn ( `Asset ${ asset . id } has no valid date, falling back to asset.fileCreatedAt` ) ;
593
- dateTimeOriginal = asset . fileCreatedAt ;
594
- localDateTime = asset . fileCreatedAt ;
592
+ // When a file is copied (but not moved) before being uploaded to immich, the target file creation
593
+ // date is set at the current timestamp, while the modification date remains untouched, so if the
594
+ // user copied the asset while he did not modified the file (like cropping, rotating and more), then
595
+ // we use the modification timestamp as it's still the original date. If the user modified the asset,
596
+ // then there is no other solution except a further manual fix.
597
+ this . logger . warn (
598
+ `No valid date found in exif tags from asset ${ asset . id } , falling back to earliest timestamp between file creation and file modification` ,
599
+ ) ;
600
+ // eslint-disable-next-line unicorn/prefer-math-min-max
601
+ const earliestDate = asset . fileModifiedAt < asset . fileCreatedAt ? asset . fileModifiedAt : asset . fileCreatedAt ;
602
+ dateTimeOriginal = earliestDate ;
603
+ localDateTime = earliestDate ;
595
604
}
596
605
597
606
this . logger . verbose ( `Asset ${ asset . id } has a local time of ${ localDateTime . toISOString ( ) } ` ) ;
0 commit comments