From 3fe06c0b94dc749733376c28af27a7975bf7267e Mon Sep 17 00:00:00 2001 From: yuankunzhang Date: Tue, 27 May 2025 22:28:01 +0800 Subject: [PATCH] fix: check whether the parsed time contains timezone --- src/items/mod.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/items/mod.rs b/src/items/mod.rs index 1044868..d06257d 100644 --- a/src/items/mod.rs +++ b/src/items/mod.rs @@ -258,10 +258,18 @@ pub fn parse(input: &mut &str) -> ModalResult> { if time_seen { return Err(expect_error(input, "time cannot appear more than once")); } - time_seen = true; + if t.offset.is_some() { + if tz_seen { + return Err(expect_error( + input, + "timezone cannot appear more than once", + )); + } tz_seen = true; } + + time_seen = true; } Item::Year(_) => { if year_seen { @@ -591,6 +599,13 @@ mod tests { .to_string() .contains("timezone cannot appear more than once")); + let result = parse(&mut "m1y"); + assert!(result.is_err()); + assert!(result + .unwrap_err() + .to_string() + .contains("timezone cannot appear more than once")); + let result = parse(&mut "2025-05-19 abcdef"); assert!(result.is_err()); assert!(result.unwrap_err().to_string().contains("unexpected input"));