#formatting #fractional #float

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

#560 in Date and time

Download history 133/week @ 2025-10-04 105/week @ 2025-10-11 161/week @ 2025-10-18 144/week @ 2025-10-25 158/week @ 2025-11-01 106/week @ 2025-11-08 139/week @ 2025-11-15 148/week @ 2025-11-22 88/week @ 2025-11-29 111/week @ 2025-12-06 109/week @ 2025-12-13 105/week @ 2025-12-20 89/week @ 2025-12-27 132/week @ 2026-01-03 130/week @ 2026-01-10 105/week @ 2026-01-17

464 downloads per month
Used in 4 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