//! Small formatting helpers shared by the commands. module cli import time pub fn stamp(unix_seconds i64) string { return time.unix(unix_seconds).local().format() } pub fn day(unix_seconds i64) string { return time.unix(unix_seconds).local().ymmdd() } pub fn clock(unix_seconds i64) string { return time.unix(unix_seconds).local().format_ss() } pub fn human_bytes(bytes i64) string { mut value := f64(bytes) mut unit := 'B' for suffix in ['KiB', 'MiB', 'GiB'] { if value < 1024 { break } value /= 1024 unit = suffix } if unit == 'B' { return '${bytes} B' } return '${value:.1f} ${unit}' } // plural renders "1 file" / "3 files". pub fn plural(count int, noun string) string { if count == 1 { return '1 ${noun}' } return '${count} ${noun}s' }