Crates.io | zuck |
lib.rs | zuck |
version | 2.0.0 |
source | src |
created_at | 2024-11-16 14:03:15.106576 |
updated_at | 2024-11-18 18:52:53.044401 |
description | Human-readable time parser and formatter |
homepage | https://github.com/LennyLizowzskiy/zuck |
repository | https://github.com/LennyLizowzskiy/zuck |
max_upload_size | |
id | 1450397 |
size | 52,813 |
Convert human-readable time to std::time::Duration
and vice versa. No dependencies needed (except std
).
This library adheres to Semantic Versioning.
Parse the &str
using [0-9][alias]
format. Whitespaces between the value are allowed between elements. Repeating time units is not.
ns
, nsec
, nsecs
, nanosec
, nanosecs
, nanosecond
, nanoseconds
μs
, us
, usec
, usecs
, microsec
, microsecs
, microsecond
, microseconds
ms
, msec
, msecs
, millisecond
, milliseconds
s
, sec
, secs
, second
, seconds
m
, min
, mins
, minute
, minutes
h
, hr
, hrs
, hour
, hours
d
, day
, days
w
, wk
, wks
, week
, weeks
mo
, month
, months
y
, yr
, yrs
, year
, years
let duration = zuck::Duration::from_str("1yr2mo3w4d5h6m7s8ms9microsec10ns").unwrap();
assert_eq!(
duration,
Duration {
nanoseconds: 10,
microseconds: 9,
milliseconds: 8,
seconds: 7,
minutes: 6,
hours: 5,
days: 25,
months: 2,
years: 1
}
);
\b(\d{1,32} ?((ns)|(nsecs?)|(nanosecs?)|(nanosecs?)|(nanoseconds?)|(μs)|(us)|(usecs?)|(microsecs?)|(microseconds?)|(ms)|(msecs?)|(milliseconds?)|(s)|(secs?)|(second)|(seconds?)|(m)|(mins?)|(minutes?)|(h)|(hrs?)|(hours?)|(d)|(days?)|(w)|(wks?)|(weeks?)|(mo)|(months?)|(y)|(yrs?)|(years?)))( ?(\d{1,32} ?((ns)|(nsecs?)|(nanosecs?)|(nanosecs?)|(nanoseconds?)|(μs)|(us)|(usecs?)|(microsecs?)|(microseconds?)|(ms)|(msecs?)|(milliseconds?)|(s)|(secs?)|(second)|(seconds?)|(m)|(mins?)|(minutes?)|(h)|(hrs?)|(hours?)|(d)|(days?)|(w)|(wks?)|(weeks?)|(mo)|(months?)|(y)|(yrs?)|(years?))))*\b
With case-insensitive flag enabled.
Though it doesn't cover the failure in case if repeating of the same time unit occurs.
This library is primarily distributed under the terms of either the MIT license or the Apache License (Version 2.0) at your option.
See LICENSE-APACHE and LICENSE-MIT for details.