Fix relative date display (#3696)
* Fix relative date display DatePeriod.days provides the number of days in the DatePeriod specifically, not the total number. LocalDate.daysUntil provides what we were looking for. * Add Changelog
This commit is contained in:
@@ -11,6 +11,8 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
|
||||
- `Other` - for technical stuff.
|
||||
|
||||
## [Unreleased]
|
||||
### Fixed
|
||||
- Fixed some dates being wrongly shown as "Today" or otherwise closer in time ([@MajorTanya](https://github.com/MajorTanya)) ([#3696](https://github.com/mihonapp/mihon/pull/3696))
|
||||
|
||||
## [v0.20.3] - 2026-08-04
|
||||
### Added
|
||||
|
||||
@@ -4,7 +4,7 @@ import android.content.Context
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.minus
|
||||
import kotlinx.datetime.daysUntil
|
||||
import kotlinx.datetime.toInstant
|
||||
import kotlinx.datetime.toJavaLocalDate
|
||||
import kotlinx.datetime.toJavaLocalDateTime
|
||||
@@ -58,7 +58,7 @@ fun LocalDate.toRelativeString(
|
||||
return dateFormat.format(this.toJavaLocalDate())
|
||||
}
|
||||
val today = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).date
|
||||
val difference = (today - this).days
|
||||
val difference = this.daysUntil(today)
|
||||
return when {
|
||||
difference < -7 -> dateFormat.format(this.toJavaLocalDate())
|
||||
difference < 0 -> context.pluralStringResource(
|
||||
|
||||
Reference in New Issue
Block a user