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:
@@ -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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user