Files
ai-app/app/androidApp/src/main/kotlin/com/example/aiapp/Durations.kt
T
irisandClaude Opus 5 edc39c7371 Thin the app's comments
The same pass the server had, on the Kotlin side: comments restating what
the code says are gone, and the ones recording a measurement, a constraint
or an incident are kept but cut to a few lines each. 6540 comment lines to
5674, and 920 lines off the app.

Two doc comments had drifted onto the item above the one they describe --
`contextAfter`'s onto `sessionWorking` in Events.kt, and `UsageMonitor`'s
equivalent on the server was fixed in the previous commit. Each is back on
its own item, which is the only non-comment line this diff moves.

The comments are reflowed to the column limit at their own indentation:
several were written wide, and ktfmt re-wrapped them into lines holding a
single orphan word. `/tmp` script, not kept -- ktfmt is idempotent over the
result, which is the check.

Left alone deliberately: this codebase's remaining comment density is high
because the comments carry things the code cannot say -- what a null means,
what a number was measured against, which bug a guard exists for. Of the
238 one-line doc comments in the app, five were pure restatement of the
name and were removed; the rest each say something the signature does not.

ktfmtFormat, compileDebugKotlin, lintDebug and testDebugUnitTest pass;
cargo test (127), clippy --all-targets and fmt still clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 16:20:16 -04:00

38 lines
1.5 KiB
Kotlin

package com.example.aiapp
/**
* A span of milliseconds, written the way somebody reads it.
*
* A tool's timeout arrives as `480000`, which nobody reads as eight minutes. The rule has two
* halves, because a short span and a long one are read for different things. Under a minute the
* question is "roughly how long", so only the largest unit is shown and a fraction carries the rest
* -- `2.5s`. At a minute or more the question is "how long exactly", so every unit with something
* in it is written out -- `5d 12h 4m`. Empty units are left out rather than written as zero.
*
* Sub-second precision is dropped past a minute: nothing that takes days is measured in
* milliseconds.
*/
fun formatMillis(ms: Long): String {
if (ms < 0) return "-" + formatMillis(-ms)
if (ms < 1000) return "${ms}ms"
if (ms < 60_000) {
val tenths = (ms + 50) / 100
val whole = tenths / 10
val rest = tenths % 10
return if (rest == 0L) "${whole}s" else "$whole.${rest}s"
}
val seconds = ms / 1000
val parts =
listOf(
"d" to seconds / 86_400,
"h" to seconds / 3600 % 24,
"m" to seconds / 60 % 60,
"s" to seconds % 60,
)
return parts.filter { it.second > 0 }.joinToString(" ") { "${it.second}${it.first}" }
}
/** [text] as a span when it is a whole number of milliseconds, and unchanged when it is not. */
fun formatMillisText(text: String): String =
text.trim().toLongOrNull()?.let { formatMillis(it) } ?: text