Skip to content

Commit

Permalink
Merge pull request #166 from patrickelectric/fix-duration
Browse files Browse the repository at this point in the history
types: duration: Deal with empty as PT0S
  • Loading branch information
DmitrySamoylov authored Sep 19, 2024
2 parents d945dca + f37004e commit 03328f5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions xsd-types/src/types/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ impl FromStr for Duration {

let mut dur: Duration = Default::default();
let mut context = ParsingContext::new();

if s.is_empty() {
return Ok(dur);
}

for (i, c) in s.chars().enumerate() {
match c {
'-' => {
Expand Down Expand Up @@ -296,6 +301,8 @@ mod tests {

#[test]
fn duration_parsing_test() {
assert_eq!(Duration::from_str(""), Duration::from_str("PT0S"));
check_valid("PT0S");
check_valid("P2Y6M5DT12H35M30S");
check_valid("P1DT2H");
check_valid("P20M");
Expand Down

0 comments on commit 03328f5

Please sign in to comment.