#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

#16 in #format-time

Download history 23/week @ 2024-11-15 51/week @ 2024-11-22 26/week @ 2024-11-29 128/week @ 2024-12-06 56/week @ 2024-12-13 81/week @ 2024-12-20 26/week @ 2024-12-27 72/week @ 2025-01-03 62/week @ 2025-01-10 65/week @ 2025-01-17 57/week @ 2025-01-24 41/week @ 2025-01-31 204/week @ 2025-02-07 95/week @ 2025-02-14 70/week @ 2025-02-21 191/week @ 2025-02-28

574 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