Skip to content

Commit 03328f5

Browse files
Merge pull request #166 from patrickelectric/fix-duration
types: duration: Deal with empty as PT0S
2 parents d945dca + f37004e commit 03328f5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

xsd-types/src/types/duration.rs

+7
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ impl FromStr for Duration {
9797

9898
let mut dur: Duration = Default::default();
9999
let mut context = ParsingContext::new();
100+
101+
if s.is_empty() {
102+
return Ok(dur);
103+
}
104+
100105
for (i, c) in s.chars().enumerate() {
101106
match c {
102107
'-' => {
@@ -296,6 +301,8 @@ mod tests {
296301

297302
#[test]
298303
fn duration_parsing_test() {
304+
assert_eq!(Duration::from_str(""), Duration::from_str("PT0S"));
305+
check_valid("PT0S");
299306
check_valid("P2Y6M5DT12H35M30S");
300307
check_valid("P1DT2H");
301308
check_valid("P20M");

0 commit comments

Comments
 (0)