From a01d0db7ce2dc5a58f204a796d4f5051d5c1acb9 Mon Sep 17 00:00:00 2001 From: Ondrej Novak Date: Thu, 19 Feb 2026 21:47:55 +0100 Subject: [PATCH] add option to list timezones --- src/cli.rs | 16 ++++++++++++++-- src/main.rs | 8 ++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index ca70df5..ac0751d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -4,6 +4,7 @@ use chrono::Local; use chrono::NaiveDate; use chrono::NaiveTime; use chrono::TimeZone; +use chrono_tz::TZ_VARIANTS; use chrono_tz::Tz; use clap::Parser; use colored::Colorize; @@ -28,7 +29,10 @@ pub struct Args { #[arg(short, long, default_value = "Local")] pub local: String, - pub time: String, + #[arg(long)] + pub list: bool, + + pub time: Option, } #[derive(PartialEq, Debug)] @@ -60,13 +64,15 @@ impl Error for CliError {} pub fn print_timezones( timezones: &Vec, - time: &String, + time: Option<&String>, date: Option<&String>, local_timezone: &String, padding_hours: i8, ) -> Result<(), CliError> { let todays_date = &get_todays_date(); let date = date.unwrap_or(todays_date); + let time_now = Local::now().format("%H:%M").to_string(); + let time = time.unwrap_or(&time_now); let parsed_time = if let Ok(hour) = time.parse::() { NaiveTime::from_hms_opt(hour, 0, 0).ok_or(CliError::CouldNotParseTime)? @@ -194,3 +200,9 @@ fn print_timetable(name: &String, name_padding_len: u32, timetable: &Vec 0 { + if args.list { + list_timezones(); + } else if args.timezone.len() > 0 { let res = print_timezones( &args.timezone, - &args.time, + args.time.as_ref(), args.date.as_ref(), &args.local, 5,