2 releases

0.1.1 Jul 17, 2021
0.1.0 Jul 17, 2021

#259 in Date and time

Download history 2828/week @ 2024-07-20 3385/week @ 2024-07-27 2739/week @ 2024-08-03 3995/week @ 2024-08-10 4321/week @ 2024-08-17 5036/week @ 2024-08-24 5494/week @ 2024-08-31 6208/week @ 2024-09-07 6806/week @ 2024-09-14 5761/week @ 2024-09-21 6554/week @ 2024-09-28 5760/week @ 2024-10-05 5797/week @ 2024-10-12 9772/week @ 2024-10-19 7795/week @ 2024-10-26 4795/week @ 2024-11-02

28,946 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