Prefer existing creationTime if tileFromFileName is close to existing time

This commit is contained in:
Neeraj Gupta 2022-12-08 10:55:32 +05:30
parent 0f72c1b4a2
commit ed76ca0b39
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
2 changed files with 21 additions and 2 deletions

View file

@ -188,12 +188,25 @@ class File extends EnteFile {
creationTime = exifTime.microsecondsSinceEpoch;
}
}
// try to get the timestamp from fileName. In case of iOS, file names are
// Try to get the timestamp from fileName. In case of iOS, file names are
// generic IMG_XXXX, so only parse it on Android devices
if (!hasExifTime && Platform.isAndroid && title != null) {
final timeFromFileName = parseDateTimeFromFileNameV2(title!);
if (timeFromFileName != null) {
creationTime = timeFromFileName.microsecondsSinceEpoch;
// only use timeFromFileName is the delta between current
// creationTime and timeFromFileName is larger than some threshold.
// This is done because many times the fileTimeStamp will only give us
// the date, not time value but the photo_manager's creation time will
// contain the time.
final bool useFileTimeStamp = creationTime == null ||
daysBetween(
DateTime.fromMicrosecondsSinceEpoch(creationTime!),
timeFromFileName,
).abs() <=
2;
if (useFileTimeStamp) {
creationTime = timeFromFileName.microsecondsSinceEpoch;
}
}
}
hash = mediaUploadData.hashData?.fileHash;

View file

@ -54,6 +54,12 @@ String getMonthAndYear(DateTime dateTime) {
return _months[dateTime.month]! + " " + dateTime.year.toString();
}
int daysBetween(DateTime from, DateTime to) {
from = DateTime(from.year, from.month, from.day);
to = DateTime(to.year, to.month, to.day);
return (to.difference(from).inHours / 24).round();
}
//Thu, 30 Jun
String getDayAndMonth(DateTime dateTime) {
return _days[dateTime.weekday]! +