Auto commit Tue Mar 24 06:01:01 PM CDT 2026
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
package com.mindmachine.mvp.session
|
||||
|
||||
import java.util.Locale
|
||||
|
||||
fun formatDuration(totalSec: Int): String {
|
||||
val sec = totalSec.coerceAtLeast(0)
|
||||
val h = sec / 3600
|
||||
val m = (sec % 3600) / 60
|
||||
val s = sec % 60
|
||||
return when {
|
||||
h > 0 -> String.format("%dh %02dm", h, m)
|
||||
m > 0 -> String.format("%dm %02ds", m, s)
|
||||
else -> String.format("%ds", s)
|
||||
val totalMinutes = sec / 60f
|
||||
|
||||
return if (totalMinutes <= 60f) {
|
||||
"${totalMinutes.toInt()} min"
|
||||
} else {
|
||||
val hours = totalMinutes / 60f
|
||||
"${formatMaxTwoDecimals(hours)} h"
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatMaxTwoDecimals(value: Float): String =
|
||||
String.format(Locale.US, "%.2f", value).trimEnd('0').trimEnd('.')
|
||||
|
||||
Reference in New Issue
Block a user