Crates.io | parse_duration0 |
lib.rs | parse_duration0 |
version | 3.0.0 |
source | src |
created_at | 2022-07-05 15:07:56.725818 |
updated_at | 2022-07-05 15:07:56.725818 |
description | Parses a duration from a string. Fork with security fix. |
homepage | https://github.com/mverleg/parse_duration/ |
repository | https://github.com/mverleg/parse_duration/ |
max_upload_size | |
id | 619751 |
size | 34,585 |
This is a fork of zeta12ti's parse_duration
.
Main differences:
This crate provides a function parse
for parsing strings into durations.
The parser is based on the standard set by
systemd.time,
but extends it significantly.
For example, negative numbers, decimals and exponents are allowed.
extern crate parse_duration;
use ::parse_duration0::parse;
use ::std::time::Duration;
// One hour less than a day
assert_eq!(parse("1 day -1 hour"), Ok(Duration::new(82_800, 0)));
// Extra things will be ignored
assert_eq!(
parse("Duration: 1 hour, 15 minutes and 29 seconds"),
Ok(Duration::new(4529, 0))
);