Skip to content

Commit 01c30c5

Browse files
committed
fix: check whether the parsed time contain timezone
1 parent e279bdf commit 01c30c5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/items/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,18 @@ pub fn parse(input: &mut &str) -> ModalResult<Vec<Item>> {
258258
if time_seen {
259259
return Err(expect_error(input, "time cannot appear more than once"));
260260
}
261-
time_seen = true;
261+
262262
if t.offset.is_some() {
263+
if tz_seen {
264+
return Err(expect_error(
265+
input,
266+
"timezone cannot appear more than once",
267+
));
268+
}
263269
tz_seen = true;
264270
}
271+
272+
time_seen = true;
265273
}
266274
Item::Year(_) => {
267275
if year_seen {
@@ -591,6 +599,13 @@ mod tests {
591599
.to_string()
592600
.contains("timezone cannot appear more than once"));
593601

602+
let result = parse(&mut "m1y");
603+
assert!(result.is_err());
604+
assert!(result
605+
.unwrap_err()
606+
.to_string()
607+
.contains("timezone cannot appear more than once"));
608+
594609
let result = parse(&mut "2025-05-19 abcdef");
595610
assert!(result.is_err());
596611
assert!(result.unwrap_err().to_string().contains("unexpected input"));

0 commit comments

Comments
 (0)