diff --git a/src/cli.rs b/src/cli.rs index 3539059..050dbe5 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -55,4 +55,7 @@ pub struct Args { #[arg(value_enum, short, long, help = "language to use")] pub lang: Option, + + #[arg(long, help = "show when the current weather conditions were measured")] + pub observation_time: bool, } diff --git a/src/lang.rs b/src/lang.rs index cd76b7a..79db7d3 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -37,6 +37,24 @@ impl Lang { Self::SV => "sv.wttr.in".to_string(), } } + pub fn observation_time(&self) -> String { + match &self { + Self::EN => "Observed at".to_string(), + Self::DE => "Beobachtet um".to_string(), + Self::PL => "Zaobserwowano o".to_string(), + Self::RU => "Наблюдается в".to_string(), + Self::TR => "Gözlemlendi".to_string(), + Self::FR => "Observé à".to_string(), + Self::BE => "Назірана ў".to_string(), + Self::ZH => "观察时间".to_string(), + Self::ES => "Observado en".to_string(), + Self::PT => "Observado em".to_string(), + Self::IT => "Osservato a".to_string(), + Self::JA => "で観察されました".to_string(), + Self::UK => "Спостерігається в".to_string(), + Self::SV => "Observerat vid".to_string(), + } + } pub fn feels_like(&self) -> String { match &self { Self::EN => "Feels Like".to_string(), diff --git a/src/main.rs b/src/main.rs index 2596cc0..81812d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -161,6 +161,19 @@ fn main() { nearest_area["country"][0]["value"].as_str().unwrap() ); + if args.observation_time { + if let Some(obs_time) = current_condition["observation_time"].as_str() { + if let Ok(time) = NaiveTime::parse_from_str(obs_time, "%I:%M %p") { + let formatted_time = if args.ampm { + obs_time.to_string() + } else { + time.format("%H:%M").to_string() + }; + tooltip += &format!("{}: {}\n", lang.observation_time(), formatted_time); + } + } + } + let now = Local::now(); let today = Local::now().date_naive();