refactor(android): add shared formatDuration + ms/sec conversion helpers

This commit is contained in:
2026-05-29 14:38:52 -04:00
parent d7dda2fcef
commit 4015fb145d
2 changed files with 50 additions and 0 deletions
@@ -0,0 +1,23 @@
package com.fabledsword.minstrel.shared
const val MILLIS_PER_SECOND = 1000
private const val SECONDS_PER_MINUTE = 60
/**
* Formats [seconds] as m:ss. Returns [zero] when [seconds] <= 0 — pass
* "--:--" for unknown track durations, "0:00" (default) for playback
* position/duration. The single mm:ss formatter for the client.
*/
fun formatDuration(seconds: Int, zero: String = "0:00"): String =
if (seconds <= 0) {
zero
} else {
"%d:%02d".format(seconds / SECONDS_PER_MINUTE, seconds % SECONDS_PER_MINUTE)
}
fun Int.secondsToMillis(): Int = this * MILLIS_PER_SECOND
fun Int.millisToSeconds(): Int = this / MILLIS_PER_SECOND
fun Long.millisToSeconds(): Int = (this / MILLIS_PER_SECOND).toInt()