#human-readable #seconds #human #readable #convert #time

secfmt

Converts seconds into a human readable format (struct) containing years, days, hours, minutes and seconds

2 releases

0.1.1 Apr 5, 2019
0.1.0 Apr 4, 2019

#493 in Date and time

Download history 22/week @ 2024-07-15 85/week @ 2024-07-22 46/week @ 2024-07-29 38/week @ 2024-08-05 24/week @ 2024-08-12 23/week @ 2024-08-19 23/week @ 2024-08-26 13/week @ 2024-09-02 19/week @ 2024-09-09 17/week @ 2024-09-16 34/week @ 2024-09-23 47/week @ 2024-09-30 18/week @ 2024-10-07 14/week @ 2024-10-14 18/week @ 2024-10-21 20/week @ 2024-10-28

72 downloads per month
Used in 2 crates

MIT license

6KB
62 lines

secfmt

Build Status Crate API License

Converts seconds into a human readable format (struct) containing years, days, hours, minutes and seconds.

Usage

Add this to your Cargo.toml:

[dependencies]
secfmt = "0.1"

Add this to your *.rs file:

extern crate secfmt;

Now you can proceed as follows:

Example 1

let seconds = 31537529;
let seconds_human_readable = secfmt::from(seconds);

Example 2

assert_eq!(1, secfmt::from(31537529).years);
assert_eq!(0, secfmt::from(31537529).days);
assert_eq!(0, secfmt::from(31537529).hours);
assert_eq!(25, secfmt::from(31537529).minutes);
assert_eq!(29, secfmt::from(31537529).seconds);

Example 3

let shr = secfmt::from(31537529);
let s = format!("{}y {}d {}h {}m {}s", shr.years, shr.days, shr.hours, shr.minutes, shr.seconds);
assert_eq!("1y 0d 0h 25m 29s", s);

Getting help

If you have questions or problems with secfmt, then I'm happy to respond to GitHub issues.

License

secfmt is distributed under the terms of the MIT license.

See LICENSE for details.

No runtime deps