Add time module with to_duration_string

Which turn a float into a `mm:ss` string
This commit is contained in:
Alexander Heldt
2025-11-23 18:52:01 +01:00
parent 26d9985a38
commit e746bfafcf
2 changed files with 55 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import gleam/float
import gleam/int
import gleam/string
pub fn to_duration_string(seconds: Float) -> String {
let total =
seconds
|> float.max(0.0)
|> float.truncate
let minutes = total / 60
let seconds = total % 60
let mins =
int.to_string(minutes)
|> string.pad_start(to: 2, with: "0")
let secs =
int.to_string(seconds)
|> string.pad_start(to: 2, with: "0")
mins <> ":" <> secs
}