1 unstable release

0.1.0 Oct 1, 2019

#34 in #duration

Download history 644/week @ 2021-08-08 463/week @ 2021-08-15 334/week @ 2021-08-22 1024/week @ 2021-08-29 513/week @ 2021-09-05 577/week @ 2021-09-12 831/week @ 2021-09-19 1105/week @ 2021-09-26 1369/week @ 2021-10-03 1098/week @ 2021-10-10 1383/week @ 2021-10-17 930/week @ 2021-10-24 500/week @ 2021-10-31 383/week @ 2021-11-07 398/week @ 2021-11-14 362/week @ 2021-11-21

450 downloads per month
Used in async-graphql

MIT license

8KB
126 lines

Build Status

iso8601-duration

Parse ISO8601 duration format.

Installation

iso8601-duration = "0.1.0"

Usage

use iso8601_duration::Duration;
use nom::{error::ErrorKind, Err};

 assert_eq!(
     Duration::parse("P23DT23H"),
     Ok(Duration::new(0., 0., 23., 23., 0., 0.))
 );
 assert_eq!(
     Duration::parse("P3Y6M4DT12H30M5S"),
     Ok(Duration::new(3., 6., 4., 12., 30., 5.))
 );
 assert_eq!(
     Duration::parse("P0.5Y"),
     Ok(Duration::new(0.5, 0., 0., 0., 0., 0.))
 );
 assert_eq!(
     Duration::parse("P0.5Y0.5M"),
     Ok(Duration::new(0.5, 0.5, 0., 0., 0., 0.))
 );
 assert_eq!(
     Duration::parse("P12W"),
     Ok(Duration::new(0., 0., 84., 0., 0., 0.))
 );

 assert_eq!(
     Duration::parse("PT"),
     Err(Err::Error(("", ErrorKind::Verify)))
 );
 assert_eq!(
     Duration::parse("P12WT12H30M5S"),
     Err(Err::Error(("T12H30M5S", ErrorKind::Eof)))
 );
 assert_eq!(
     Duration::parse("P0.5S0.5M"),
     Err(Err::Error(("0.5S0.5M", ErrorKind::Verify)))
 );
 assert_eq!(
     Duration::parse("P0.5A"),
     Err(Err::Error(("0.5A", ErrorKind::Verify)))
 );

License: MIT

Dependencies

~705KB
~14K SLoC

]]