Skip to content

Commit

Permalink
Add observation time tooltip (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevithakannan2 authored Nov 18, 2024
1 parent 627e8d5 commit 7e0e13f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ pub struct Args {

#[arg(value_enum, short, long, help = "language to use")]
pub lang: Option<Lang>,

#[arg(long, help = "show when the current weather conditions were measured")]
pub observation_time: bool,
}
18 changes: 18 additions & 0 deletions src/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
13 changes: 13 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7e0e13f

Please sign in to comment.