Crates.io | ms-converter |
lib.rs | ms-converter |
version | 1.4.0 |
source | src |
created_at | 2020-03-11 18:17:37.843007 |
updated_at | 2020-05-02 11:22:26.911141 |
description | Fast abstraction for converting human-like times into milliseconds. |
homepage | https://mnwa.github.io/ms/ |
repository | https://github.com/Mnwa/ms |
max_upload_size | |
id | 217620 |
size | 29,572 |
Fast abstraction for converting human-like times into milliseconds.
Like, are 1d
to 86400000
.
There are two ways to calculate milliseconds:
crate::ms_converter::ms
crate::ms_converter::ms_expr
Add this to your Cargo.toml:
[dependencies]
ms-converter = "1.4"
use crate::ms_converter::ms;
let value = ms("1d").unwrap();
assert_eq!(value, 86400000)
use crate::ms_converter::ms_expr;
const VALUE: i64 = ms_expr!(i64, 1 d);
assert_eq!(VALUE, 86400000)
time.Duration
use crate::ms_converter::ms_into_time;
let value = ms_into_time("1d").unwrap();
assert_eq!(value.as_millis(), 86400000)
use crate::ms_converter::{get_duration_by_postfix, DAY};
let value = get_duration_by_postfix(DAY as i64, " day").unwrap();
assert_eq!(value, "1 day")
use crate::ms_converter::{get_max_possible_duration, DAY};
let value = get_max_possible_duration(DAY as i64).unwrap();
assert_eq!(value, "1d")
use crate::ms_converter::{get_max_possible_duration_long, WEEK};
let value = get_max_possible_duration_long(2 * WEEK as i64).unwrap();
assert_eq!(value, "14 days") // Max possible period is a day
years
, year
, yrs
, yr
, y
weeks
, week
, w
days
, day
, d
hours
, hour
, hrs
, hr
, h
minutes
, minute
, mins
, min
, m
seconds
, second
, secs
, sec
, s
milliseconds
, millisecond
, msecs
, msec
, ms
and empty postfixYou can check the performance diff between ms_converter
and ms
libraries here.
Also, the macro has no time in the runtime! It will be converted into the const value.
cargo test
Running code style tests
cargo fmt --all -- --check
Just create pr or issue. You welcome.
We use SemVer for versioning. For the versions available, see the tags on this repository.
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details