feat: More fine grained time display
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user