@@ -88,52 +88,49 @@ fun LocalDateTime.toRelativeString(
8888 return dateFormat.format(this )
8989 }
9090 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())
9293 return when {
93- difference < - 7 -> dateFormat.format(this )
94- difference < - 1 -> context.pluralStringResource(
94+ timeDifference < - 7 -> dateFormat.format(this )
95+ timeDifference < 0 -> context.pluralStringResource(
9596 MR .plurals.upcoming_relative_time,
96- difference .toInt().absoluteValue,
97- difference .toInt().absoluteValue,
97+ dateDifference .toInt().absoluteValue,
98+ dateDifference .toInt().absoluteValue,
9899 )
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 -> {
117101 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,
124107 )
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(
127124 MR .plurals.relative_time_hours,
128125 hourDifference.toInt(),
129126 hourDifference.toInt(),
130127 )
131128 }
132129 }
133- difference < 7 -> context.resources.getQuantityString(
130+ timeDifference < 7 -> context.resources.getQuantityString(
134131 R .plurals.relative_time,
135- difference .toInt(),
136- difference .toInt(),
132+ dateDifference .toInt(),
133+ dateDifference .toInt(),
137134 )
138135 else -> dateFormat.format(this )
139136 }
0 commit comments