mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-30 13:07:43 -06:00
Merge PR #2044: Reject impossible hour/minute/second in normalize_iso
This commit is contained in:
@@ -233,6 +233,15 @@ mod tests {
|
||||
assert_eq!(iso_seconds("2026-01-01T10:00+02:00"), iso_seconds("2026-01-01T10:00"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn impossible_times_are_rejected_not_rolled_over() {
|
||||
for bad in ["2026-04-01T10:75:00", "2026-04-01 10:00:75", "2026-04-01T10:60", "2026-04-01T24:00:00", "2026-04-01T10:59:60"] {
|
||||
assert_eq!(normalize_iso(bad), None, "{bad}");
|
||||
assert_eq!(shift_iso(bad, 5), None, "{bad}");
|
||||
}
|
||||
assert_eq!(normalize_iso("2026-04-01T23:59:59").as_deref(), Some("2026-04-01T23:59:59"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runs_by_day_month_year_keep_stacks_together() {
|
||||
let mut c = Catalog::new();
|
||||
|
||||
@@ -296,6 +296,9 @@ pub fn iso_seconds(s: &str) -> Option<i64> {
|
||||
}
|
||||
let (hh, mm, ss) =
|
||||
if s.len() >= 16 { (num(11, 13)?, num(14, 16)?, if s.get(16..17) == Some(":") { num(17, 19).unwrap_or(0) } else { 0 }) } else { (0, 0, 0) };
|
||||
if hh >= 24 || mm >= 60 || ss >= 60 {
|
||||
return None;
|
||||
}
|
||||
// days from civil (proleptic Gregorian)
|
||||
let y2 = if m <= 2 { y - 1 } else { y };
|
||||
let era = y2.div_euclid(400);
|
||||
|
||||
Reference in New Issue
Block a user