feat: More fine grained time display

This commit is contained in:
Linnea Gräf
2024-11-10 17:32:05 +01:00
parent 4d0a73030d
commit d1241fb0d9
2 changed files with 54 additions and 48 deletions

View File

@@ -1,10 +1,9 @@
package moe.nea.firmament.util
import com.google.common.math.IntMath.pow
import kotlin.math.absoluteValue
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
object FirmFormatters {
fun formatCommas(int: Int, segments: Int = 3): String = formatCommas(int.toLong(), segments)
@@ -48,10 +47,17 @@ object FirmFormatters {
if (minutes > 0) {
sb.append(minutes).append("m")
}
sb.append(seconds).append("s")
val milliTime = nanoseconds / 1_000_000
val deciseconds = milliTime / 100
if (millis) {
sb.append(nanoseconds / 1_000_000).append("ms")
sb.append(seconds).append("s")
sb.append(milliTime).append("ms")
} else if (duration.absoluteValue < 5.seconds && deciseconds != 0) {
sb.append(seconds).append('.').append(deciseconds.digitToChar()).append("s")
} else {
sb.append(seconds).append("s")
}
Unit
}
return sb.toString()
}

View File

@@ -90,7 +90,7 @@ fun CharSequence.removeColorCodes(keepNonColorCodes: Boolean = false): String {
}
val Text.unformattedString: String
get() = string.removeColorCodes()
get() = string.removeColorCodes() // TODO: maybe shortcircuit this with .visit
val Text.directLiteralStringContent: String? get() = (this.content as? PlainTextContent)?.string()