ms-convert 0.1.0

Convert human-readable time strings to milliseconds and vice versa, inspired by vercel/ms
Documentation
  • Coverage
  • 50%
    4 out of 8 items documented3 out of 4 items with examples
  • Size
  • Source code size: 15.45 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.59 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • t-seki/ms-convert
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • t-seki

ms-convert

Convert human-readable time strings to milliseconds and vice versa. A Rust port of vercel/ms.

Zero dependencies.

Usage

Add to your Cargo.toml:

[dependencies]
ms-convert = "0.1"

Parse a time string to milliseconds

use ms_convert::parse;

assert_eq!(parse("2d").unwrap(), 172_800_000.0);
assert_eq!(parse("1.5h").unwrap(), 5_400_000.0);
assert_eq!(parse("1 hour").unwrap(), 3_600_000.0);

Format milliseconds to a human-readable string

use ms_convert::format;

assert_eq!(format(60_000.0, false), "1m");
assert_eq!(format(60_000.0, true), "1 minute");
assert_eq!(format(172_800_000.0, true), "2 days");

Supported Units

Short Long (singular / plural)
ms millisecond / milliseconds
s sec / second / seconds
m min / minute / minutes
h hr / hour / hours
d day / days
w week / weeks
mo month / months
y year / years

License

MIT