#duration #format-time #format #go

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

#11 in #format-time

Download history 2/week @ 2024-02-02 7/week @ 2024-02-09 18/week @ 2024-02-16 46/week @ 2024-02-23 19/week @ 2024-03-01 38/week @ 2024-03-08 46/week @ 2024-03-15 30/week @ 2024-03-22 68/week @ 2024-03-29 27/week @ 2024-04-05 16/week @ 2024-04-12 16/week @ 2024-04-19 14/week @ 2024-04-26 12/week @ 2024-05-03 29/week @ 2024-05-10 47/week @ 2024-05-17

105 downloads per month
Used in 2 crates (via darklua)

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