#time #format-time

durationfmt

A Rust library to format std::time::Duration the same way Go does

2 releases

Uses old Rust 2015

0.1.1 Oct 21, 2017
0.1.0 Oct 21, 2017

#17 in #format-time

Download history 7/week @ 2024-09-09 6/week @ 2024-09-16 27/week @ 2024-09-23 9/week @ 2024-09-30 1/week @ 2024-10-07 40/week @ 2024-10-14 28/week @ 2024-10-21 13/week @ 2024-10-28 47/week @ 2024-11-04 4/week @ 2024-11-11 48/week @ 2024-11-18 40/week @ 2024-11-25 17/week @ 2024-12-02 144/week @ 2024-12-09 63/week @ 2024-12-16 69/week @ 2024-12-23

299 downloads per month
Used in 6 crates (4 directly)

MIT license

7KB
129 lines

durationfmt

A Rust library to format std::time::Duration the same way Go does.

This is almost a verbatim copy of the algorithm Go uses.

Usage

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;

Example

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
}

No runtime deps