mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-22 15:09:22 +01:00
Shorten memory album time range
This commit is contained in:
parent
5ba2e3639a
commit
541b1d61fe
3 changed files with 74 additions and 74 deletions
|
@ -59,8 +59,8 @@ class PopulateAlbum {
|
||||||
assert(album.provider is AlbumMemoryProvider);
|
assert(album.provider is AlbumMemoryProvider);
|
||||||
final provider = album.provider as AlbumMemoryProvider;
|
final provider = album.provider as AlbumMemoryProvider;
|
||||||
final date = DateTime(provider.year, provider.month, provider.day);
|
final date = DateTime(provider.year, provider.month, provider.day);
|
||||||
final from = date.subtract(const Duration(days: 3));
|
final from = date.subtract(const Duration(days: 2));
|
||||||
final to = date.add(const Duration(days: 4));
|
final to = date.add(const Duration(days: 3));
|
||||||
final files = await FileAppDbDataSource(appDb).listByDate(account,
|
final files = await FileAppDbDataSource(appDb).listByDate(account,
|
||||||
from.millisecondsSinceEpoch, to.millisecondsSinceEpoch);
|
from.millisecondsSinceEpoch, to.millisecondsSinceEpoch);
|
||||||
return files
|
return files
|
||||||
|
|
|
@ -41,7 +41,7 @@ class MemoryAlbumHelper {
|
||||||
}
|
}
|
||||||
for (final dy in [0, -1, 1]) {
|
for (final dy in [0, -1, 1]) {
|
||||||
if (today.copyWith(year: date.year + dy).difference(date).abs().inDays <=
|
if (today.copyWith(year: date.year + dy).difference(date).abs().inDays <=
|
||||||
3) {
|
2) {
|
||||||
_log.fine(
|
_log.fine(
|
||||||
"[addFile] Add file (${f.bestDateTime}) to ${date.year + dy}");
|
"[addFile] Add file (${f.bestDateTime}) to ${date.year + dy}");
|
||||||
_addFileToYear(f, date.year + dy);
|
_addFileToYear(f, date.year + dy);
|
||||||
|
|
|
@ -14,21 +14,21 @@ void main() {
|
||||||
test("next year", _nextYear);
|
test("next year", _nextYear);
|
||||||
group("prev year", () {
|
group("prev year", () {
|
||||||
test("same day", _prevYear);
|
test("same day", _prevYear);
|
||||||
test("-4 day", _prevYear4DaysBefore);
|
|
||||||
test("-3 day", _prevYear3DaysBefore);
|
test("-3 day", _prevYear3DaysBefore);
|
||||||
test("+4 day", _prevYear4DaysAfter);
|
test("-2 day", _prevYear2DaysBefore);
|
||||||
test("+3 day", _prevYear3DaysAfter);
|
test("+3 day", _prevYear3DaysAfter);
|
||||||
|
test("+2 day", _prevYear2DaysAfter);
|
||||||
});
|
});
|
||||||
group("on feb 29", () {
|
group("on feb 29", () {
|
||||||
test("+feb 25", _onFeb29AddFeb25);
|
|
||||||
test("+feb 26", _onFeb29AddFeb26);
|
test("+feb 26", _onFeb29AddFeb26);
|
||||||
|
test("+feb 27", _onFeb29AddFeb27);
|
||||||
group("non leap year", () {
|
group("non leap year", () {
|
||||||
test("+mar 5", _onFeb29AddMar5);
|
|
||||||
test("+mar 4", _onFeb29AddMar4);
|
test("+mar 4", _onFeb29AddMar4);
|
||||||
|
test("+mar 3", _onFeb29AddMar3);
|
||||||
});
|
});
|
||||||
group("leap year", () {
|
group("leap year", () {
|
||||||
test("+mar 4", _onFeb29AddMar4LeapYear);
|
|
||||||
test("+mar 3", _onFeb29AddMar3LeapYear);
|
test("+mar 3", _onFeb29AddMar3LeapYear);
|
||||||
|
test("+mar 2", _onFeb29AddMar2LeapYear);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
group("on jan 1", () {
|
group("on jan 1", () {
|
||||||
|
@ -99,31 +99,31 @@ void _prevYear() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a file taken in the prev year
|
|
||||||
///
|
|
||||||
/// Today: 2021-02-03
|
|
||||||
/// File: 2020-01-30
|
|
||||||
/// Expect: empty
|
|
||||||
void _prevYear4DaysBefore() {
|
|
||||||
final today = DateTime(2021, 2, 3);
|
|
||||||
final obj = MemoryAlbumHelper(today);
|
|
||||||
final file = util.buildJpegFile(
|
|
||||||
path: "", fileId: 0, lastModified: DateTime.utc(2020, 1, 30));
|
|
||||||
obj.addFile(file);
|
|
||||||
expect(obj.build(_nameBuilder), []);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add a file taken in the prev year
|
/// Add a file taken in the prev year
|
||||||
///
|
///
|
||||||
/// Today: 2021-02-03
|
/// Today: 2021-02-03
|
||||||
/// File: 2020-01-31
|
/// File: 2020-01-31
|
||||||
/// Expect: [2020]
|
/// Expect: empty
|
||||||
void _prevYear3DaysBefore() {
|
void _prevYear3DaysBefore() {
|
||||||
final today = DateTime(2021, 2, 3);
|
final today = DateTime(2021, 2, 3);
|
||||||
final obj = MemoryAlbumHelper(today);
|
final obj = MemoryAlbumHelper(today);
|
||||||
final file = util.buildJpegFile(
|
final file = util.buildJpegFile(
|
||||||
path: "", fileId: 0, lastModified: DateTime.utc(2020, 1, 31));
|
path: "", fileId: 0, lastModified: DateTime.utc(2020, 1, 31));
|
||||||
obj.addFile(file);
|
obj.addFile(file);
|
||||||
|
expect(obj.build(_nameBuilder), []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add a file taken in the prev year
|
||||||
|
///
|
||||||
|
/// Today: 2021-02-03
|
||||||
|
/// File: 2020-02-01
|
||||||
|
/// Expect: [2020]
|
||||||
|
void _prevYear2DaysBefore() {
|
||||||
|
final today = DateTime(2021, 2, 3);
|
||||||
|
final obj = MemoryAlbumHelper(today);
|
||||||
|
final file = util.buildJpegFile(
|
||||||
|
path: "", fileId: 0, lastModified: DateTime.utc(2020, 2, 1));
|
||||||
|
obj.addFile(file);
|
||||||
expect(
|
expect(
|
||||||
obj
|
obj
|
||||||
.build(_nameBuilder)
|
.build(_nameBuilder)
|
||||||
|
@ -145,28 +145,28 @@ void _prevYear3DaysBefore() {
|
||||||
/// Add a file taken in the prev year
|
/// Add a file taken in the prev year
|
||||||
///
|
///
|
||||||
/// Today: 2021-02-03
|
/// Today: 2021-02-03
|
||||||
/// File: 2020-01-30
|
/// File: 2020-02-06
|
||||||
/// Expect: empty
|
/// Expect: empty
|
||||||
void _prevYear4DaysAfter() {
|
|
||||||
final today = DateTime(2021, 2, 3);
|
|
||||||
final obj = MemoryAlbumHelper(today);
|
|
||||||
final file = util.buildJpegFile(
|
|
||||||
path: "", fileId: 0, lastModified: DateTime.utc(2020, 2, 7));
|
|
||||||
obj.addFile(file);
|
|
||||||
expect(obj.build(_nameBuilder), []);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add a file taken in the prev year
|
|
||||||
///
|
|
||||||
/// Today: 2021-02-03
|
|
||||||
/// File: 2020-01-31
|
|
||||||
/// Expect: [2020]
|
|
||||||
void _prevYear3DaysAfter() {
|
void _prevYear3DaysAfter() {
|
||||||
final today = DateTime(2021, 2, 3);
|
final today = DateTime(2021, 2, 3);
|
||||||
final obj = MemoryAlbumHelper(today);
|
final obj = MemoryAlbumHelper(today);
|
||||||
final file = util.buildJpegFile(
|
final file = util.buildJpegFile(
|
||||||
path: "", fileId: 0, lastModified: DateTime.utc(2020, 2, 6));
|
path: "", fileId: 0, lastModified: DateTime.utc(2020, 2, 6));
|
||||||
obj.addFile(file);
|
obj.addFile(file);
|
||||||
|
expect(obj.build(_nameBuilder), []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add a file taken in the prev year
|
||||||
|
///
|
||||||
|
/// Today: 2021-02-03
|
||||||
|
/// File: 2020-02-05
|
||||||
|
/// Expect: [2020]
|
||||||
|
void _prevYear2DaysAfter() {
|
||||||
|
final today = DateTime(2021, 2, 3);
|
||||||
|
final obj = MemoryAlbumHelper(today);
|
||||||
|
final file = util.buildJpegFile(
|
||||||
|
path: "", fileId: 0, lastModified: DateTime.utc(2020, 2, 5));
|
||||||
|
obj.addFile(file);
|
||||||
expect(
|
expect(
|
||||||
obj
|
obj
|
||||||
.build(_nameBuilder)
|
.build(_nameBuilder)
|
||||||
|
@ -185,31 +185,31 @@ void _prevYear3DaysAfter() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a file taken in the prev year
|
|
||||||
///
|
|
||||||
/// Today: 2020-02-29
|
|
||||||
/// File: 2019-02-25
|
|
||||||
/// Expect: empty
|
|
||||||
void _onFeb29AddFeb25() {
|
|
||||||
final today = DateTime(2020, 2, 29);
|
|
||||||
final obj = MemoryAlbumHelper(today);
|
|
||||||
final file = util.buildJpegFile(
|
|
||||||
path: "", fileId: 0, lastModified: DateTime.utc(2019, 2, 25));
|
|
||||||
obj.addFile(file);
|
|
||||||
expect(obj.build(_nameBuilder), []);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add a file taken in the prev year
|
/// Add a file taken in the prev year
|
||||||
///
|
///
|
||||||
/// Today: 2020-02-29
|
/// Today: 2020-02-29
|
||||||
/// File: 2019-02-26
|
/// File: 2019-02-26
|
||||||
/// Expect: [2019]
|
/// Expect: empty
|
||||||
void _onFeb29AddFeb26() {
|
void _onFeb29AddFeb26() {
|
||||||
final today = DateTime(2020, 2, 29);
|
final today = DateTime(2020, 2, 29);
|
||||||
final obj = MemoryAlbumHelper(today);
|
final obj = MemoryAlbumHelper(today);
|
||||||
final file = util.buildJpegFile(
|
final file = util.buildJpegFile(
|
||||||
path: "", fileId: 0, lastModified: DateTime.utc(2019, 2, 26));
|
path: "", fileId: 0, lastModified: DateTime.utc(2019, 2, 26));
|
||||||
obj.addFile(file);
|
obj.addFile(file);
|
||||||
|
expect(obj.build(_nameBuilder), []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add a file taken in the prev year
|
||||||
|
///
|
||||||
|
/// Today: 2020-02-29
|
||||||
|
/// File: 2019-02-27
|
||||||
|
/// Expect: [2019]
|
||||||
|
void _onFeb29AddFeb27() {
|
||||||
|
final today = DateTime(2020, 2, 29);
|
||||||
|
final obj = MemoryAlbumHelper(today);
|
||||||
|
final file = util.buildJpegFile(
|
||||||
|
path: "", fileId: 0, lastModified: DateTime.utc(2019, 2, 27));
|
||||||
|
obj.addFile(file);
|
||||||
expect(
|
expect(
|
||||||
obj
|
obj
|
||||||
.build(_nameBuilder)
|
.build(_nameBuilder)
|
||||||
|
@ -228,31 +228,31 @@ void _onFeb29AddFeb26() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a file taken in the prev year
|
|
||||||
///
|
|
||||||
/// Today: 2020-02-29
|
|
||||||
/// File: 2019-03-05
|
|
||||||
/// Expect: empty
|
|
||||||
void _onFeb29AddMar5() {
|
|
||||||
final today = DateTime(2020, 2, 29);
|
|
||||||
final obj = MemoryAlbumHelper(today);
|
|
||||||
final file = util.buildJpegFile(
|
|
||||||
path: "", fileId: 0, lastModified: DateTime.utc(2019, 3, 5));
|
|
||||||
obj.addFile(file);
|
|
||||||
expect(obj.build(_nameBuilder), []);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add a file taken in the prev year
|
/// Add a file taken in the prev year
|
||||||
///
|
///
|
||||||
/// Today: 2020-02-29
|
/// Today: 2020-02-29
|
||||||
/// File: 2019-03-04
|
/// File: 2019-03-04
|
||||||
/// Expect: [2019]
|
/// Expect: empty
|
||||||
void _onFeb29AddMar4() {
|
void _onFeb29AddMar4() {
|
||||||
final today = DateTime(2020, 2, 29);
|
final today = DateTime(2020, 2, 29);
|
||||||
final obj = MemoryAlbumHelper(today);
|
final obj = MemoryAlbumHelper(today);
|
||||||
final file = util.buildJpegFile(
|
final file = util.buildJpegFile(
|
||||||
path: "", fileId: 0, lastModified: DateTime.utc(2019, 3, 4));
|
path: "", fileId: 0, lastModified: DateTime.utc(2019, 3, 4));
|
||||||
obj.addFile(file);
|
obj.addFile(file);
|
||||||
|
expect(obj.build(_nameBuilder), []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add a file taken in the prev year
|
||||||
|
///
|
||||||
|
/// Today: 2020-02-29
|
||||||
|
/// File: 2019-03-03
|
||||||
|
/// Expect: [2019]
|
||||||
|
void _onFeb29AddMar3() {
|
||||||
|
final today = DateTime(2020, 2, 29);
|
||||||
|
final obj = MemoryAlbumHelper(today);
|
||||||
|
final file = util.buildJpegFile(
|
||||||
|
path: "", fileId: 0, lastModified: DateTime.utc(2019, 3, 3));
|
||||||
|
obj.addFile(file);
|
||||||
expect(
|
expect(
|
||||||
obj
|
obj
|
||||||
.build(_nameBuilder)
|
.build(_nameBuilder)
|
||||||
|
@ -274,13 +274,13 @@ void _onFeb29AddMar4() {
|
||||||
/// Add a file taken in the prev leap year
|
/// Add a file taken in the prev leap year
|
||||||
///
|
///
|
||||||
/// Today: 2020-02-29
|
/// Today: 2020-02-29
|
||||||
/// File: 2016-03-04
|
/// File: 2016-03-03
|
||||||
/// Expect: empty
|
/// Expect: empty
|
||||||
void _onFeb29AddMar4LeapYear() {
|
void _onFeb29AddMar3LeapYear() {
|
||||||
final today = DateTime(2020, 2, 29);
|
final today = DateTime(2020, 2, 29);
|
||||||
final obj = MemoryAlbumHelper(today);
|
final obj = MemoryAlbumHelper(today);
|
||||||
final file = util.buildJpegFile(
|
final file = util.buildJpegFile(
|
||||||
path: "", fileId: 0, lastModified: DateTime.utc(2016, 3, 4));
|
path: "", fileId: 0, lastModified: DateTime.utc(2016, 3, 3));
|
||||||
obj.addFile(file);
|
obj.addFile(file);
|
||||||
expect(obj.build(_nameBuilder), []);
|
expect(obj.build(_nameBuilder), []);
|
||||||
}
|
}
|
||||||
|
@ -288,13 +288,13 @@ void _onFeb29AddMar4LeapYear() {
|
||||||
/// Add a file taken in the prev leap year
|
/// Add a file taken in the prev leap year
|
||||||
///
|
///
|
||||||
/// Today: 2020-02-29
|
/// Today: 2020-02-29
|
||||||
/// File: 2016-03-03
|
/// File: 2016-03-02
|
||||||
/// Expect: [2016]
|
/// Expect: [2016]
|
||||||
void _onFeb29AddMar3LeapYear() {
|
void _onFeb29AddMar2LeapYear() {
|
||||||
final today = DateTime(2020, 2, 29);
|
final today = DateTime(2020, 2, 29);
|
||||||
final obj = MemoryAlbumHelper(today);
|
final obj = MemoryAlbumHelper(today);
|
||||||
final file = util.buildJpegFile(
|
final file = util.buildJpegFile(
|
||||||
path: "", fileId: 0, lastModified: DateTime.utc(2016, 3, 3));
|
path: "", fileId: 0, lastModified: DateTime.utc(2016, 3, 2));
|
||||||
obj.addFile(file);
|
obj.addFile(file);
|
||||||
expect(
|
expect(
|
||||||
obj
|
obj
|
||||||
|
|
Loading…
Reference in a new issue