Do time color calculation with TZ aware time value.

This commit is contained in:
2019-09-23 13:43:58 -07:00
parent c4920a1e6e
commit 4790d35fa7
2 changed files with 15 additions and 17 deletions

View File

@@ -47,27 +47,28 @@ impl DateTimeWidget {
impl Widget for DateTimeWidget {
fn update(&mut self) -> Option<WidgetUpdate> {
let now = chrono::Local::now();
let (time, time_string) = match &self.tz {
Some(tz) => {
let tz: Tz = tz.parse().unwrap();
let now = chrono::Local::now();
let now = now.with_timezone(&tz);
(now.time(), now.format(&self.fmt).to_string())
}
None => {
let now = chrono::Local::now();
(now.time(), now.format(&self.fmt).to_string())
}
};
let color = if let Some(colors) = &self.colors {
colors
.iter()
.filter(|tc| tc.start < now.time())
.filter(|tc| tc.start < time)
.last()
.map(|tc| tc.color.clone())
} else {
None
};
let time_string = match &self.tz {
Some(tz) => {
let tz: Tz = tz.parse().unwrap();
let now = now.with_timezone(&tz);
//TODO(wathiede): convert to timezone.
now.format(&self.fmt).to_string()
}
None => now.format(&self.fmt).to_string(),
};
let mut data = Block::new().append_full_text(&time_string).clone();
if let Some(color) = color {
data.color(color);