Format negative durations correctly

formatDuration() previously emitted strings like '00:-49' for negative
values because the modulo operations propagated the sign. This shows up
on live streams that briefly report a negative position during reload,
and as the basis for a planned 'behind live edge' indicator.

Recurse on the absolute value when negative so we get a clean -MM:SS
(or -HH:MM:SS) format.
This commit is contained in:
Simon Gardling
2026-05-01 00:14:28 -04:00
parent cf3fc61f6a
commit 7a6b185e9d
@@ -251,6 +251,11 @@ fun String.fixHtmlWhitespace(): Spanned {
} }
fun Long.formatDuration(): String { fun Long.formatDuration(): String {
// Negative durations show up for live streams seeked behind the seek-window start, or
// briefly while the player is reseating. Recurse on the absolute value so we get a clean
// `-MM:SS` instead of garbage like `00:-49`.
if (this < 0) return "-" + (-this).formatDuration()
val hours = this / 3600000 val hours = this / 3600000
val minutes = (this % 3600000) / 60000 val minutes = (this % 3600000) / 60000
val seconds = (this % 60000) / 1000 val seconds = (this % 60000) / 1000