Skip to content

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

License

Notifications You must be signed in to change notification settings

kdar/durationfmt-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.git" }

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
}

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages