Prefer existing creationTime if tileFromFileName is close to existing time
This commit is contained in:
parent
0f72c1b4a2
commit
ed76ca0b39
|
@ -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;
|
||||
|
|
|
@ -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]! +
|
||||
|
|
Loading…
Reference in a new issue