Time zone name instead of offset in time display
This commit is contained in:
parent
be96618f76
commit
c33360fb7b
@ -11,4 +11,6 @@ serde_json = "1.0.113"
|
|||||||
curl = "0.4.46"
|
curl = "0.4.46"
|
||||||
regex = "1.11.1"
|
regex = "1.11.1"
|
||||||
chrono = "0.4.41"
|
chrono = "0.4.41"
|
||||||
|
chrono-tz = "0.10.3"
|
||||||
|
iana-time-zone = "0.1.63"
|
||||||
clap = { version = "4.5.1", features = ["derive"] }
|
clap = { version = "4.5.1", features = ["derive"] }
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
use chrono::{DateTime, Local};
|
use chrono::{DateTime, TimeZone, Local, Utc};
|
||||||
use crate::common;
|
use crate::common;
|
||||||
use crate::bar_modules;
|
use crate::bar_modules;
|
||||||
|
use chrono_tz::{OffsetName, Tz};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct UnibarModuleTime {
|
pub struct UnibarModuleTime {
|
||||||
opts: common::AppOptions,
|
opts: common::AppOptions,
|
||||||
date_time: DateTime<Local>,
|
date_time: DateTime<Local>,
|
||||||
|
time_zone: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UnibarModuleTime {
|
impl UnibarModuleTime {
|
||||||
@ -14,6 +16,7 @@ impl UnibarModuleTime {
|
|||||||
UnibarModuleTime {
|
UnibarModuleTime {
|
||||||
opts: o,
|
opts: o,
|
||||||
date_time: Local::now(),
|
date_time: Local::now(),
|
||||||
|
time_zone: "".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23,10 +26,23 @@ impl bar_modules::BarModuleActions for UnibarModuleTime {
|
|||||||
// --------------------
|
// --------------------
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
self.date_time = Local::now();
|
self.date_time = Local::now();
|
||||||
|
self.time_zone = "".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
fn generate_data(&mut self) {
|
fn generate_data(&mut self) {
|
||||||
|
match iana_time_zone::get_timezone() {
|
||||||
|
Ok(tz_str) => {
|
||||||
|
let tz: Tz = tz_str.parse().expect("Trouble parsing timezone string");
|
||||||
|
let offset = tz.offset_from_utc_date(&Utc::now().date_naive());
|
||||||
|
self.time_zone = offset.abbreviation()
|
||||||
|
.expect("Trouble abbreviating timezone")
|
||||||
|
.to_string();
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Trouble getting timezone: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
if self.opts.debug {
|
if self.opts.debug {
|
||||||
println!("-----> Time dump {:#?}", self.date_time);
|
println!("-----> Time dump {:#?}", self.date_time);
|
||||||
}
|
}
|
||||||
@ -34,7 +50,7 @@ impl bar_modules::BarModuleActions for UnibarModuleTime {
|
|||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
fn get_content(&self) -> String {
|
fn get_content(&self) -> String {
|
||||||
return format!("{}", self.date_time.format("%I:%M%p %Z"));
|
return format!("{} {}", self.date_time.format("%I:%M%p"), self.time_zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user