Function iso8601::duration

source ·
pub fn duration(string: &str) -> Result<Duration, String>
Expand description

Parses a duration string.

A string starts with P and can have one of the following formats:

  • Fully-specified duration: P1Y2M3DT4H5M6S
  • Duration in weekly intervals: P1W
  • Fully-specified duration in DateTime format: P<datetime>

Both fully-specified formats get parsed into the YMDHMS Duration variant. The weekly interval format gets parsed into the Weeks Duration variant.

The ranges for each of the individual units are not expected to exceed the next largest unit.

These ranges (inclusive) are as follows:

  • Year (any valid u32)
  • Month 0 - 12
  • Week 0 - 52
  • Day 0 - 31
  • Hour 0 - 24
  • Minute 0 - 60
  • Second 0 - 60

§Examples

let duration = iso8601::duration("P1Y2M3DT4H5M6S").unwrap();
let duration = iso8601::duration("P1W").unwrap();
let duration = iso8601::duration("P2015-11-03T21:56").unwrap();