2 releases

0.1.1 Jul 17, 2021
0.1.0 Jul 17, 2021

#11 in #duration-string

Download history 4521/week @ 2024-06-12 3838/week @ 2024-06-19 3021/week @ 2024-06-26 2200/week @ 2024-07-03 2618/week @ 2024-07-10 2829/week @ 2024-07-17 3325/week @ 2024-07-24 2798/week @ 2024-07-31 2876/week @ 2024-08-07 4657/week @ 2024-08-14 4186/week @ 2024-08-21 5779/week @ 2024-08-28 5157/week @ 2024-09-04 6556/week @ 2024-09-11 6514/week @ 2024-09-18 5460/week @ 2024-09-25

24,982 downloads per month
Used in 9 crates (4 directly)

MIT license

10KB
171 lines

parse-duration-rs

parse-duration-rs is a Rust port of Golang parse duration time.ParseDuration. It parses a duration string in a short form such as 100ms, 1h45m, and 3ns and return duration in nanoseconds.

The crate is called go-parse-duration and you can depend on it via cargo:

[dependencies]
go-parse-duration = "0.1"

Example

use go_parse_duration::{parse_duration, Error};

fn parse() -> Result<i64, Error> {
  let d = parse_duration("300us")?;
  Ok(d)
}

Usage with Chrono

Converting to Chrono duration can be done easily:

use chrono::Duration;
use go_parse_duration::{parse_duration, Error};

fn parse() -> Result<Duration, Error> {
  let d = parse_duration("1m")?;
  Ok(Duration::nanoseconds(d))
}

Author

Armin Primadi https://github.com/aprimadi (@ Sahamee)


lib.rs:

parse-duration-rs is a Rust port of Golang parse duration time.ParseDuration. It parses a duration string in a short form such as 100ms, 1h45m, and 3ns and return duration in nanoseconds.

The crate is called go-parse-duration and you can depend on it via cargo:

[dependencies]
go-parse-duration = "0.1"

Example

use go_parse_duration::{parse_duration, Error};

fn parse() -> Result<i64, Error> {
  let d = parse_duration("300us")?;
  Ok(d)
}

Usage with Chrono

Converting to Chrono duration can be done easily:

use chrono::Duration;
use go_parse_duration::{parse_duration, Error};

fn parse() -> Result<Duration, Error> {
  let d = parse_duration("1m")?;
  Ok(Duration::nanoseconds(d))
}

No runtime deps