Fast abstraction for converting human-like times into milliseconds.
Like, are 1d
to 86400000
.
There are two ways to calculate milliseconds:
* In the runtime crate::ms_converter::ms
* In the compilation time crate::ms_converter::ms_expr
Add this to your Cargo.toml:
toml
[dependencies]
ms-converter = "1.0"
```rust use crate::ms_converter::ms;
let value = ms("1d").unwrap(); assert_eq!(value, 86400000) ```
```rust use crate::msconverter::msexpr;
const VALUE: i64 = msexpr!(i64, 1 d); asserteq!(VALUE, 86400000) ```
time.Duration
```rust use crate::msconverter::msinto_time;
let value = msintotime("1d").unwrap(); asserteq!(value.asmillis(), 86400000) ```
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.
bash
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