Skip to content

Commit

Permalink
fix: Some issues with relative date calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
jmir1 committed Jul 16, 2024
1 parent 1f3be7b commit 03e1ecd
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions app/src/main/java/eu/kanade/tachiyomi/util/lang/DateExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,52 +88,49 @@ fun LocalDateTime.toRelativeString(
return dateFormat.format(this)
}
val now = LocalDateTime.now()
val difference = ChronoUnit.DAYS.between(this, now)
val timeDifference = ChronoUnit.DAYS.between(this, now)
val dateDifference = ChronoUnit.DAYS.between(this.toLocalDate(), now.toLocalDate())
return when {
difference < -7 -> dateFormat.format(this)
difference < -1 -> context.pluralStringResource(
timeDifference < -7 -> dateFormat.format(this)
timeDifference < 0 -> context.pluralStringResource(
MR.plurals.upcoming_relative_time,
difference.toInt().absoluteValue,
difference.toInt().absoluteValue,
dateDifference.toInt().absoluteValue,
dateDifference.toInt().absoluteValue,
)
difference < 0 -> {
val hourDifference = ChronoUnit.HOURS.between(now, this)
if (hourDifference < 1) {
val minuteDifference = ChronoUnit.MINUTES.between(now, this)
context.pluralStringResource(
MR.plurals.upcoming_relative_time_minutes,
minuteDifference.toInt(),
minuteDifference.toInt(),
)
} else {
context.pluralStringResource(
MR.plurals.upcoming_relative_time_hours,
hourDifference.toInt(),
hourDifference.toInt(),
)
}
}
difference < 1 -> {
timeDifference < 1 -> {
val hourDifference = ChronoUnit.HOURS.between(this, now)
if (hourDifference < 1) {
val minuteDifference = ChronoUnit.MINUTES.between(this, now)
context.pluralStringResource(
MR.plurals.relative_time_minutes,
minuteDifference.toInt(),
minuteDifference.toInt(),
when {
hourDifference < 0 -> context.pluralStringResource(
MR.plurals.upcoming_relative_time_hours,
hourDifference.toInt().absoluteValue,
hourDifference.toInt().absoluteValue,
)
} else {
context.pluralStringResource(
hourDifference < 1 -> {
val minuteDifference = ChronoUnit.MINUTES.between(this, now)
when {
minuteDifference < 0 -> context.pluralStringResource(
MR.plurals.upcoming_relative_time_minutes,
minuteDifference.toInt().absoluteValue,
minuteDifference.toInt().absoluteValue,
)
else -> context.pluralStringResource(
MR.plurals.relative_time_minutes,
minuteDifference.toInt(),
minuteDifference.toInt(),
)
}
}
else -> context.pluralStringResource(
MR.plurals.relative_time_hours,
hourDifference.toInt(),
hourDifference.toInt(),
)
}
}
difference < 7 -> context.resources.getQuantityString(
timeDifference < 7 -> context.resources.getQuantityString(
R.plurals.relative_time,
difference.toInt(),
difference.toInt(),
dateDifference.toInt(),
dateDifference.toInt(),
)
else -> dateFormat.format(this)
}
Expand Down

0 comments on commit 03e1ecd

Please sign in to comment.