8 stable releases

Uses old Rust 2015

2.1.1 Mar 25, 2021
2.1.0 Feb 21, 2020
2.0.1 Sep 23, 2019
1.0.3 Sep 9, 2019
0.1.0 Aug 14, 2017

⚠️ Issues reported

#176 in Parser implementations

Download history 14659/week @ 2022-08-15 17145/week @ 2022-08-22 12989/week @ 2022-08-29 11021/week @ 2022-09-05 10647/week @ 2022-09-12 8931/week @ 2022-09-19 7698/week @ 2022-09-26 7357/week @ 2022-10-03 8342/week @ 2022-10-10 7231/week @ 2022-10-17 10713/week @ 2022-10-24 9821/week @ 2022-10-31 10866/week @ 2022-11-07 9774/week @ 2022-11-14 10820/week @ 2022-11-21 10154/week @ 2022-11-28

42,682 downloads per month
Used in 52 crates (30 directly)

MIT license

37KB
450 lines

parse_duration

Crates.io Travis

IMPORTANT: This repository is no longer being updated. Before deciding to use it, check if any of the issues are deal breakers. In particular, this crate should not be used with untrusted input (see this issue).

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_duration::parse;
use std::time::Duration;

// One hour less than a day
assert_eq!(parse("1 day -1 hour"), Ok(Duration::new(82_800, 0)));
// Using exponents
assert_eq!(parse("1.26e-1 days"), Ok(Duration::new(10_886, 400_000_000)));
// Extra things will be ignored
assert_eq!(
    parse("Duration: 1 hour, 15 minutes and 29 seconds"),
    Ok(Duration::new(4529, 0))
);

Documentation

Documentation may be found on docs.rs.

Minimum Rust version policy

This crate's minimum supported rustc version is 1.28.0.

If the minimum rustc version needs to be increased, there will be a new major version. For example, if parse_duration 2.0.0 requires rustc 1.28.0, then parse_duration 2.x.y will also only require rustc 1.28.0. Since this crate is fairly simple, there likely won't be any need to increase the minimum version in the foreseeable future.

License

This software is licensed under the MIT License.

Contributing

Feel free to file an issue or submit a pull request if there's a bug you want fixed or a feature you want implemented.

By contributing to this project, you agree to license your code under the terms of the MIT License.

Dependencies

~1.3–1.8MB
~47K SLoC