JackDauer
Use this Rust crate to easily parse various time formats to durations.
Demo
use duration;
use Duration;
let nanoseconds = duration;
let milliseconds = duration;
let seconds = duration;
let minutes = duration;
let hours = duration;
let day = duration;
let week = duration;
let month = duration;
let year = duration;
let real_big_duration = duration;
let real_small_duration = duration;
Features
- The
durationfunction provides straight forward functions to parse durations from a human-readable format, into std::time::Duration instances. - The time unit specific functions return unsigned integers representing the amount of said time unit parsed from a human-readable format:
years: returns the parsed duration as an amount of yearsmonths: returns the parsed duration as an amount of monthsweeks: returns the parsed duration as an amount of weeksdays: returns the parsed duration as an amount of dayshours: returns the parsed duration as an amount of hoursminutes: returns the parsed duration as an amount of minutesseconds: returns the parsed duration as an amount of secondsmilliseconds: returns the parsed duration as an amount of yearsnanoseconds: returns the parsed duration as an amount of years
Installation
Add it as a dependency to your Cargo.toml
[]
= "0.1.0"
Documentation
Authors
FAQ
What's the name about?
"Dauer" is the German word for duration. When thinking about time, it reminded me of this show called "24", and its main character "Jack Bauer" (which, incidentally also happens to mean "builder" in German). The contraction of both gives "Jack Dauer".
But why the ridiculous name?
It's 2021, COVID-19 is still raging out there. The last year and a half has been quite gloomy, and I thought I needed (and you needed too; maybe you're not just aware of it) of some terrible pun to shed some light on my day to day quarantined life.
Acknowledgements
- This crate wouldn't have been possible without Nom, the parser combinator library
- Inspiration taken from the awesome ms javascript library
- readme.so, a superb tool that helped me build this README