@@ -88,52 +88,49 @@ fun LocalDateTime.toRelativeString(
88
88
return dateFormat.format(this )
89
89
}
90
90
val now = LocalDateTime .now()
91
- val difference = ChronoUnit .DAYS .between(this , now)
91
+ val timeDifference = ChronoUnit .DAYS .between(this , now)
92
+ val dateDifference = ChronoUnit .DAYS .between(this .toLocalDate(), now.toLocalDate())
92
93
return when {
93
- difference < - 7 -> dateFormat.format(this )
94
- difference < - 1 -> context.pluralStringResource(
94
+ timeDifference < - 7 -> dateFormat.format(this )
95
+ timeDifference < 0 -> context.pluralStringResource(
95
96
MR .plurals.upcoming_relative_time,
96
- difference .toInt().absoluteValue,
97
- difference .toInt().absoluteValue,
97
+ dateDifference .toInt().absoluteValue,
98
+ dateDifference .toInt().absoluteValue,
98
99
)
99
- difference < 0 -> {
100
- val hourDifference = ChronoUnit .HOURS .between(now, this )
101
- if (hourDifference < 1 ) {
102
- val minuteDifference = ChronoUnit .MINUTES .between(now, this )
103
- context.pluralStringResource(
104
- MR .plurals.upcoming_relative_time_minutes,
105
- minuteDifference.toInt(),
106
- minuteDifference.toInt(),
107
- )
108
- } else {
109
- context.pluralStringResource(
110
- MR .plurals.upcoming_relative_time_hours,
111
- hourDifference.toInt(),
112
- hourDifference.toInt(),
113
- )
114
- }
115
- }
116
- difference < 1 -> {
100
+ timeDifference < 1 -> {
117
101
val hourDifference = ChronoUnit .HOURS .between(this , now)
118
- if (hourDifference < 1 ) {
119
- val minuteDifference = ChronoUnit .MINUTES .between(this , now)
120
- context.pluralStringResource(
121
- MR .plurals.relative_time_minutes,
122
- minuteDifference.toInt(),
123
- minuteDifference.toInt(),
102
+ when {
103
+ hourDifference < 0 -> context.pluralStringResource(
104
+ MR .plurals.upcoming_relative_time_hours,
105
+ hourDifference.toInt().absoluteValue,
106
+ hourDifference.toInt().absoluteValue,
124
107
)
125
- } else {
126
- context.pluralStringResource(
108
+ hourDifference < 1 -> {
109
+ val minuteDifference = ChronoUnit .MINUTES .between(this , now)
110
+ when {
111
+ minuteDifference < 0 -> context.pluralStringResource(
112
+ MR .plurals.upcoming_relative_time_minutes,
113
+ minuteDifference.toInt().absoluteValue,
114
+ minuteDifference.toInt().absoluteValue,
115
+ )
116
+ else -> context.pluralStringResource(
117
+ MR .plurals.relative_time_minutes,
118
+ minuteDifference.toInt(),
119
+ minuteDifference.toInt(),
120
+ )
121
+ }
122
+ }
123
+ else -> context.pluralStringResource(
127
124
MR .plurals.relative_time_hours,
128
125
hourDifference.toInt(),
129
126
hourDifference.toInt(),
130
127
)
131
128
}
132
129
}
133
- difference < 7 -> context.resources.getQuantityString(
130
+ timeDifference < 7 -> context.resources.getQuantityString(
134
131
R .plurals.relative_time,
135
- difference .toInt(),
136
- difference .toInt(),
132
+ dateDifference .toInt(),
133
+ dateDifference .toInt(),
137
134
)
138
135
else -> dateFormat.format(this )
139
136
}
0 commit comments