2 releases

0.1.1 Jul 17, 2021
0.1.0 Jul 17, 2021

#299 in Date and time

Download history 5939/week @ 2024-11-15 6641/week @ 2024-11-22 6424/week @ 2024-11-29 6801/week @ 2024-12-06 6232/week @ 2024-12-13 2479/week @ 2024-12-20 3156/week @ 2024-12-27 4752/week @ 2025-01-03 5431/week @ 2025-01-10 5495/week @ 2025-01-17 6063/week @ 2025-01-24 6427/week @ 2025-01-31 6344/week @ 2025-02-07 5384/week @ 2025-02-14 5700/week @ 2025-02-21 5190/week @ 2025-02-28

23,877 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