From 583bc8866adb47bac1ff956561e2abbc81b7f1da Mon Sep 17 00:00:00 2001 From: Ondrej Novak Date: Thu, 19 Feb 2026 22:15:44 +0100 Subject: [PATCH] add upper bound to the padding option --- src/cli.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cli.rs b/src/cli.rs index 5f59c89..2e93a43 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -40,6 +40,7 @@ pub struct Args { pub enum CliError { CouldNotParseTime, CouldNotParseDate, + PaddingTooLarge, CouldNotParseTimezone(String), CouldNotGenerateTimetable(String), } @@ -49,6 +50,7 @@ impl fmt::Display for CliError { let message = match *self { Self::CouldNotParseTime => "Couldn't parse time".to_string(), Self::CouldNotParseDate => "Couldn't parse date".to_string(), + Self::PaddingTooLarge => "Padding option cannot be larger than 12".to_string(), Self::CouldNotParseTimezone(ref tz) => { format!("Couldn't parse timezone {}", tz).to_string() } @@ -70,6 +72,10 @@ pub fn print_timezones( local_timezone: &String, padding_hours: i8, ) -> Result<(), CliError> { + if padding_hours > 12 { + return Err(CliError::PaddingTooLarge); + }; + let parsed_time = if let Some(t) = time { if let Ok(hour) = t.parse::() { NaiveTime::from_hms_opt(hour, 0, 0).ok_or(CliError::CouldNotParseTime)?