[Refactor] Move UTC hour calculation to the clock module

This commit is contained in:
Gergely Polonkai 2022-05-24 10:39:16 +02:00
parent d56c6ef087
commit b485b01c2f
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
2 changed files with 10 additions and 2 deletions

View File

@ -1,7 +1,11 @@
use chrono::{prelude::Local, Timelike};
use chrono::{
prelude::{Local, Utc},
Timelike,
};
pub enum DayPart {
LocalNow,
UtcNow,
}
pub fn get_moon_phase() -> f32 {
@ -17,6 +21,10 @@ pub fn get_seconds_since_midnight(which: DayPart) -> i32 {
let seconds = match which {
DayPart::LocalNow => local_timestamp.time().num_seconds_from_midnight(),
DayPart::UtcNow => local_timestamp
.with_timezone(&Utc)
.time()
.num_seconds_from_midnight(),
};
seconds as i32

View File

@ -342,7 +342,7 @@ pub fn gen_svg(
hour_name_path_cache: &[(PathData, PathData); 24],
) -> Document {
let local_timestamp = Local::now();
let utc_hour = local_timestamp.with_timezone(&Utc).time().hour();
let (utc_hour, _, _) = get_hms(DayPart::UtcNow);
let (local_hour, local_minute, local_second) = get_hms(DayPart::LocalNow);
let unixtime = suncalc::Timestamp(local_timestamp.timestamp_millis());