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,22 +2,22 @@ use crate::color::Color;
use crate::draw::{Font, ROBOTO_REGULAR};
use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, WaitContext, Widget};
use chrono::{DateTime, Datelike, Local};
use chrono::{Datelike, NaiveDateTime};
pub struct Date {
cur_time: DateTime<Local>,
cur_time: NaiveDateTime,
date_cache: Font,
size: f32,
}
impl Date {
pub fn new(size: f32) -> Box<Date> {
pub fn new(time: &NaiveDateTime, size: f32) -> Box<Date> {
let mut date_cache = Font::new(&ROBOTO_REGULAR, size);
date_cache
.add_str_to_cache("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,/ ");
Box::new(Date {
cur_time: Local::now(),
cur_time: time.clone(),
date_cache: date_cache,
size: size,
})