Improve creationTime fallback logic
This commit is contained in:
parent
e42a1106dc
commit
fe34ddaeae
3 changed files with 38 additions and 13 deletions
|
@ -11,7 +11,7 @@ const String sentryTunnel = "https://sentry-reporter.ente.io";
|
|||
const String roadmapURL = "https://roadmap.ente.io";
|
||||
const int microSecondsInDay = 86400000000;
|
||||
const int android11SDKINT = 30;
|
||||
const int jan011971Time = 31580904000000;
|
||||
const int jan011991Time = 662668200000000;
|
||||
const int galleryLoadStartTime = -8000000000000000; // Wednesday, March 6, 1748
|
||||
const int galleryLoadEndTime = 9223372036854775807; // 2^63 -1
|
||||
|
||||
|
|
|
@ -74,24 +74,40 @@ class File extends EnteFile {
|
|||
file.deviceFolder = pathName;
|
||||
file.location = Location(asset.latitude, asset.longitude);
|
||||
file.fileType = _fileTypeFromAsset(asset);
|
||||
file.creationTime = asset.createDateTime.microsecondsSinceEpoch;
|
||||
if (file.creationTime == null || (file.creationTime! <= jan011971Time)) {
|
||||
try {
|
||||
final parsedDateTime = parseDateTimeFromFileNameV2(
|
||||
basenameWithoutExtension(file.title ?? ""),
|
||||
);
|
||||
file.creationTime = parsedDateTime?.microsecondsSinceEpoch ??
|
||||
DateTime.now().millisecondsSinceEpoch;
|
||||
} catch (e) {
|
||||
file.creationTime = DateTime.now().millisecondsSinceEpoch;
|
||||
}
|
||||
}
|
||||
file.creationTime = fileCreationTime(file.title, asset);
|
||||
file.modificationTime = asset.modifiedDateTime.microsecondsSinceEpoch;
|
||||
file.fileSubType = asset.subtype;
|
||||
file.metadataVersion = kCurrentMetadataVersion;
|
||||
return file;
|
||||
}
|
||||
|
||||
static int fileCreationTime(String? fileTitle, AssetEntity asset) {
|
||||
int creationTime = asset.createDateTime.microsecondsSinceEpoch;
|
||||
if (creationTime >= jan011991Time) {
|
||||
// assuming that fileSystem is returning correct creationTime.
|
||||
// During upload, this might get overridden with exif Creation time
|
||||
return creationTime;
|
||||
} else {
|
||||
if (asset.modifiedDateTime.millisecondsSinceEpoch >= jan011991Time) {
|
||||
creationTime = asset.modifiedDateTime.millisecondsSinceEpoch;
|
||||
} else {
|
||||
creationTime = DateTime.now().toUtc().millisecondsSinceEpoch;
|
||||
}
|
||||
try {
|
||||
final parsedDateTime = parseDateTimeFromFileNameV2(
|
||||
basenameWithoutExtension(fileTitle ?? ""),
|
||||
);
|
||||
if (parsedDateTime != null) {
|
||||
creationTime = parsedDateTime.microsecondsSinceEpoch;
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
static FileType _fileTypeFromAsset(AssetEntity asset) {
|
||||
FileType type = FileType.image;
|
||||
switch (asset.type) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:photos/core/constants.dart';
|
||||
import 'package:photos/utils/date_time_util.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
|
@ -28,4 +29,12 @@ void main() {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("verify constants", () {
|
||||
expect(
|
||||
jan011991Time,
|
||||
DateTime(1991, 1, 1).toUtc().microsecondsSinceEpoch,
|
||||
reason: "constant mismatch",
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue