aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorEmpa <42304516+ItsEmpa@users.noreply.github.com>2024-06-16 19:15:16 +0200
committerGitHub <noreply@github.com>2024-06-16 19:15:16 +0200
commitd93d586451dd4b79b023af0af8a3a680f9e7951c (patch)
tree6b1281e62cda1fd14af0e8b333121cf32fe7e602 /src/main/java
parentbe99826efa13edbff6f04ed6c1eb254d12316a71 (diff)
downloadskyhanni-d93d586451dd4b79b023af0af8a3a680f9e7951c.tar.gz
skyhanni-d93d586451dd4b79b023af0af8a3a680f9e7951c.tar.bz2
skyhanni-d93d586451dd4b79b023af0af8a3a680f9e7951c.zip
Fix: Duration Format below 1s (#2110)
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
index a2c1633d7..3af450db4 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
@@ -34,16 +34,16 @@ object TimeUtils {
var currentUnits = 0
val result = buildString {
for ((unit, value) in parts) {
- if (value != 0) {
- val formatted = unit.format(value, longName)
- append(formatted)
- if (unit == TimeUnit.SECOND && showMilliSeconds) {
- val formattedMillis = (millis / 100).toInt()
- deleteCharAt(lastIndex)
- append(".${formattedMillis}s")
- }
-
- append(" ")
+ if (value != 0 || (unit == TimeUnit.SECOND && showMilliSeconds)) {
+ val formatted = value.addSeparators()
+ val formattedMillis = (millis / 100).toInt()
+ val name = unit.getName(value, longName)
+
+ val text = if (unit == TimeUnit.SECOND && showMilliSeconds) {
+ "$formatted.$formattedMillis"
+ } else formatted
+
+ append("$text$name ")
if (maxUnits != -1 && ++currentUnits == maxUnits) break
}
}
@@ -160,9 +160,9 @@ enum class TimeUnit(val factor: Long, val shortName: String, val longName: Strin
SECOND(FACTOR_SECONDS, "s", "Second"),
;
- fun format(value: Int, longFormat: Boolean = false) = if (longFormat) {
- "${value.addSeparators()} $longName" + if (value > 1) "s" else ""
- } else {
- "${value.addSeparators()}$shortName"
- }
+ fun getName(value: Int, longFormat: Boolean) = if (longFormat) {
+ " $longName" + if (value > 1) "s" else ""
+ } else shortName
+
+ fun format(value: Int, longFormat: Boolean = false) = value.addSeparators() + getName(value, longFormat)
}