Fix off by 1 dates (fixes #6791)

This commit is contained in:
arkon 2022-03-24 18:49:00 -04:00
parent 8e332dba30
commit 5c0a43e8d6
3 changed files with 4 additions and 4 deletions

View file

@ -66,7 +66,7 @@ class HistoryPresenter : BasePresenter<HistoryController>() {
.map { recents -> .map { recents ->
val map = TreeMap<Date, MutableList<MangaChapterHistory>> { d1, d2 -> d2.compareTo(d1) } val map = TreeMap<Date, MutableList<MangaChapterHistory>> { d1, d2 -> d2.compareTo(d1) }
val byDay = recents val byDay = recents
.groupByTo(map, { it.history.last_read.toDateKey() }) .groupByTo(map) { it.history.last_read.toDateKey() }
byDay.flatMap { entry -> byDay.flatMap { entry ->
val dateItem = DateSectionItem(entry.key, relativeTime, dateFormat) val dateItem = DateSectionItem(entry.key, relativeTime, dateFormat)
entry.value.map { HistoryItem(it, dateItem) } entry.value.map { HistoryItem(it, dateItem) }

View file

@ -84,7 +84,7 @@ class UpdatesPresenter : BasePresenter<UpdatesController>() {
.map { mangaChapters -> .map { mangaChapters ->
val map = TreeMap<Date, MutableList<MangaChapter>> { d1, d2 -> d2.compareTo(d1) } val map = TreeMap<Date, MutableList<MangaChapter>> { d1, d2 -> d2.compareTo(d1) }
val byDay = mangaChapters val byDay = mangaChapters
.groupByTo(map, { it.chapter.date_fetch.toDateKey() }) .groupByTo(map) { it.chapter.date_fetch.toDateKey() }
byDay.flatMap { entry -> byDay.flatMap { entry ->
val dateItem = DateSectionItem(entry.key, relativeTime, dateFormat) val dateItem = DateSectionItem(entry.key, relativeTime, dateFormat)
entry.value entry.value

View file

@ -112,8 +112,8 @@ fun Date.toRelativeString(
val days = difference.floorDiv(MILLISECONDS_IN_DAY).toInt() val days = difference.floorDiv(MILLISECONDS_IN_DAY).toInt()
return when { return when {
difference < 0 -> context.getString(R.string.recently) difference < 0 -> context.getString(R.string.recently)
difference < MILLISECONDS_IN_DAY -> context.getString(R.string.relative_time_today) difference <= MILLISECONDS_IN_DAY -> context.getString(R.string.relative_time_today)
difference < MILLISECONDS_IN_DAY.times(range) -> context.resources.getQuantityString( difference <= MILLISECONDS_IN_DAY.times(range) -> context.resources.getQuantityString(
R.plurals.relative_time, R.plurals.relative_time,
days, days,
days days