use serde::Serialize;
use time::OffsetDateTime;
pub fn json<T: Serialize>(v: &T) {
println!("{}", serde_json::to_string_pretty(v).expect("serializable"));
}
pub fn warn(msg: impl AsRef<str>) {
eprintln!("warning: {}", msg.as_ref());
}
pub fn ts(t: OffsetDateTime) -> String {
let fmt = time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]");
t.format(&fmt).unwrap_or_default()
}
pub fn size(bytes: u64) -> String {
match bytes {
b if b >= 1024 * 1024 => format!("{:.1} MB", b as f64 / (1024.0 * 1024.0)),
b if b >= 1024 => format!("{:.1} KB", b as f64 / 1024.0),
b => format!("{b} B"),
}
}