Skip to content

Commit 81f48d4

Browse files
committed
refactor: non-plural pretty duration
1 parent 300e4a9 commit 81f48d4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/main/kotlin/spp/protocol/utils/TimeUtils.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,30 @@ fun Double.fromPerSecondToPrettyFrequency(translate: (String) -> String = { it }
3030
}
3131
}
3232

33-
fun Long.toPrettyDuration(translate: (String) -> String = { it }): String {
33+
fun Long.toPrettyDuration(translate: (String) -> String = { it }, pluralize: Boolean = true): String {
3434
val days = this / 86400000.0
3535
if (days > 1) {
36-
return "${days.toInt()}" + translate("dys")
36+
return "${days.toInt()}" + if (pluralize) translate("dys") else translate("dy")
3737
} else if (days == 1.0) {
3838
return "${days.toInt()}" + translate("dy")
3939
}
4040
val hours = this / 3600000.0
4141
if (hours > 1) {
42-
return "${hours.toInt()}" + translate("hrs")
42+
return "${hours.toInt()}" + if (pluralize) translate("hrs") else translate("hr")
4343
} else if (hours == 1.0) {
4444
return "${hours.toInt()}" + translate("hr")
4545
}
4646
val minutes = this / 60000.0
4747
if (minutes > 1) {
48-
return "${minutes.toInt()}" + translate("mins")
48+
return "${minutes.toInt()}" + if (pluralize) translate("mins") else translate("min")
4949
} else if (minutes == 1.0) {
5050
return "${minutes.toInt()}" + translate("min")
5151
}
5252
val seconds = this / 1000.0
5353
if (seconds > 1) {
54-
return "${seconds.toInt()}" + translate("secs")
54+
return "${seconds.toInt()}" + if (pluralize) translate("s") else translate("s")
5555
} else if (seconds == 1.0) {
56-
return "${seconds.toInt()}" + translate("sec")
56+
return "${seconds.toInt()}" + translate("s")
5757
}
5858
return "$this" + translate("ms")
5959
}

0 commit comments

Comments
 (0)