Convert DateTime<Local> to NaiveDateTime

Use of DateTime<Local> can lead to excessive inspection of the system
timezone.

Instead, propagate only a timezone-compensated NaiveDateTime throughout
the widgets.
This commit is contained in:
Kenny Levinsen
2020-04-22 00:52:08 +02:00
parent c380d20794
commit 300711affe
7 changed files with 35 additions and 29 deletions
+4 -4
View File
@@ -2,21 +2,21 @@ use crate::color::Color;
use crate::draw::{Font, ROBOTO_REGULAR};
use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, WaitContext, Widget};
use chrono::{DateTime, Duration, Local, Timelike};
use chrono::{Duration, NaiveDateTime, Timelike};
pub struct Clock {
cur_time: DateTime<Local>,
cur_time: NaiveDateTime,
clock_cache: Font,
size: f32,
}
impl Clock {
pub fn new(size: f32) -> Box<Clock> {
pub fn new(time: &NaiveDateTime, size: f32) -> Box<Clock> {
let mut clock_cache = Font::new(&ROBOTO_REGULAR, size);
clock_cache.add_str_to_cache("0123456789:");
Box::new(Clock {
cur_time: Local::now(),
cur_time: time.clone(),
clock_cache: clock_cache,
size: size,
})