A call's duration that rounds to sixty seconds is "1m 00s", never "60.0s"

Tenths, rounded half up, decide the form (59.96 s is a minute).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Fable 5.2 committed 2026-11-12 10:38:47 +00:00
1 parent 0437f802a4
commit 3e15900521
2 files changed
+9 -4

No files matched your search

@@ -45,11 +45,13 @@ fun ToolCall.state(): String = when {
*/
fun callDuration(state: String, ms: Long?): String? {
if (ms == null || state == "running" || state == "denied") return null
val seconds = ms.coerceAtLeast(0) / 1000.0
if (seconds < 60) return String.format(Locale.ROOT, "%.1fs", seconds)
val minutes = (seconds / 60).toLong()
// Tenths, rounded half up, decide the form: 59.96 s is not "60.0s" but a minute.
val tenths = (ms.coerceAtLeast(0) + 50) / 100
if (tenths < 600) return "${tenths / 10}.${tenths % 10}s"
val seconds = (ms / 1000).coerceAtLeast(60)
val minutes = seconds / 60
return if (minutes < 60) {
String.format(Locale.ROOT, "%dm %02ds", minutes, (seconds % 60).toLong())
String.format(Locale.ROOT, "%dm %02ds", minutes, seconds % 60)
} else {
String.format(Locale.ROOT, "%dh %02dm", minutes / 60, minutes % 60)
}
@@ -49,6 +49,9 @@ class DisplayTest {
assertEquals("0.4s", callDuration("done", 412))
assertEquals("8.4s", callDuration("done", 8_449))
assertEquals("59.9s", callDuration("failed", 59_940))
// What would round to sixty seconds is a minute, never "60.0s".
assertEquals("1m 00s", callDuration("done", 59_960))
assertEquals("1m 00s", callDuration("done", 60_000))
assertEquals("1m 05s", callDuration("done", 65_000))
assertEquals("2h 03m", callDuration("done", 7_380_000))
assertEquals("1.2s", callDuration("failed", 1_200))