#time #float #fmt #formatting #fractional

floating-duration

Converts durations to fractional numbers and allows automatic formatting of durations

3 releases

Uses old Rust 2015

0.1.2 Mar 20, 2018
0.1.1 Apr 16, 2017
0.1.0 Apr 15, 2017

#54 in Date and time

Download history 370/week @ 2021-02-15 407/week @ 2021-02-22 290/week @ 2021-03-01 321/week @ 2021-03-08 224/week @ 2021-03-15 351/week @ 2021-03-22 199/week @ 2021-03-29 171/week @ 2021-04-05 228/week @ 2021-04-12 325/week @ 2021-04-19 122/week @ 2021-04-26 143/week @ 2021-05-03 245/week @ 2021-05-10 146/week @ 2021-05-17 142/week @ 2021-05-24 113/week @ 2021-05-31

1,118 downloads per month
Used in less than 7 crates

MIT/Apache

9KB
54 lines

floating-duration

Build Status Crates.io MIT/Apache Docs.rs

Allows converting a Duration to floating-point seconds, milliseconds and microseconds. Additionally, it allows automatic formatting of a Duration (it automatically chooses a unit).

Usage

Minimum Rust version: 1.8.0

Add this crate to Cargo.toml

[dependencies]
floating-duration = "0.1.2"

Now you can easily print a Duration:

extern crate floating_duration;

use std::time::Instant;

use floating_duration::{TimeAsFloat, TimeFormat};

fn main() {
    let start = Instant::now();
    
    let result = (1..12).fold(1, |acc, x| acc * x);
    
    println!("Needed {}", TimeFormat(start.elapsed()));
    println!("In seconds: {}", start.elapsed().as_fractional_secs());
}

Contribution

Contribution is very welcome!

Any contribution you submit is assumed to be dual-licensed under MIT/Apache-2.

License

floating-duration is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT.

No runtime deps