Crates.io | durationfmt |
lib.rs | durationfmt |
version | 0.1.1 |
source | src |
created_at | 2017-10-21 23:34:43.57317 |
updated_at | 2017-10-21 23:59:14.843709 |
description | A Rust library to format std::time::Duration the same way Go does. |
homepage | |
repository | https://github.com/kdar/durationfmt-rs |
max_upload_size | |
id | 36517 |
size | 7,770 |
A Rust library to format std::time::Duration the same way Go does.
This is almost a verbatim copy of the algorithm Go uses.
Add to your Cargo.toml file:
[dependencies]
durationfmt = { git = "https://github.com/kdar/durationfmt-rs", branch = "master"}
and this to your crate root:
extern crate durationfmt;
extern crate durationfmt;
use std::time::Duration;
fn main() {
let d = Duration::new(0, 0);
println!("{}", durationfmt::to_string(d));
// 0s
let d = Duration::new(90, 0);
println!("{}", durationfmt::to_string(d));
// 1m30s
let d = Duration::new(209, 1_000);
println!("{}", durationfmt::to_string(d));
// 3m29.000001s
}