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:
@@ -3,10 +3,10 @@ use crate::color::Color;
|
||||
use crate::draw::{Font, DEJAVUSANS_MONO, ROBOTO_REGULAR};
|
||||
use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, WaitContext, Widget};
|
||||
|
||||
use chrono::{Date, Datelike, Local};
|
||||
use chrono::{Datelike, NaiveDate, NaiveDateTime};
|
||||
|
||||
pub struct Calendar {
|
||||
cur_date: Date<Local>,
|
||||
cur_date: NaiveDate,
|
||||
dirty: bool,
|
||||
offset: f64,
|
||||
sections: u32,
|
||||
@@ -22,8 +22,8 @@ impl Calendar {
|
||||
&self,
|
||||
buf: &mut Buffer,
|
||||
background_color: &Color,
|
||||
orig: &Date<Local>,
|
||||
time: &Date<Local>,
|
||||
orig: &NaiveDate,
|
||||
time: &NaiveDate,
|
||||
) -> Result<(i32, i32, i32, i32), ::std::io::Error> {
|
||||
let mut time = time.clone();
|
||||
let mut y_off = 1;
|
||||
@@ -153,7 +153,7 @@ impl Calendar {
|
||||
}
|
||||
|
||||
impl Calendar {
|
||||
pub fn new(font_size: f32, sections: u32) -> Box<Calendar> {
|
||||
pub fn new(time: &NaiveDateTime, font_size: f32, sections: u32) -> Box<Calendar> {
|
||||
let mut calendar_cache = Font::new(&DEJAVUSANS_MONO, font_size * 2.0);
|
||||
calendar_cache.add_str_to_cache("0123456789");
|
||||
let mut month_cache = Font::new(&ROBOTO_REGULAR, font_size * 4.0);
|
||||
@@ -163,7 +163,7 @@ impl Calendar {
|
||||
let mut day_cache = Font::new(&DEJAVUSANS_MONO, font_size);
|
||||
day_cache.add_str_to_cache("MONTUEWDHFRISA");
|
||||
Box::new(Calendar {
|
||||
cur_date: Local::now().date(),
|
||||
cur_date: time.date(),
|
||||
dirty: true,
|
||||
offset: 0.0,
|
||||
sections: sections,
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
+4
-4
@@ -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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user