[Refactor] Move local time calculation to the clock module

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

View File

@ -21,3 +21,14 @@ pub fn get_seconds_since_midnight(which: DayPart) -> i32 {
seconds as i32 seconds as i32
} }
pub fn get_hms(which: DayPart) -> (u8, u8, u8) {
let mut seconds = get_seconds_since_midnight(which);
let hours = seconds / 3600;
seconds -= hours * 3600;
let minutes = seconds / 60;
seconds -= hours * 60;
(hours as u8, minutes as u8, seconds as u8)
}

View File

@ -17,7 +17,7 @@ use svg::{
}; };
use usvg::Tree; use usvg::Tree;
use crate::clock::{get_moon_phase, get_seconds_since_midnight, DayPart}; use crate::clock::{get_hms, get_moon_phase, get_seconds_since_midnight, DayPart};
use crate::config::Config; use crate::config::Config;
const HOUR_NAMES: [&str; 24] = [ const HOUR_NAMES: [&str; 24] = [
@ -343,9 +343,7 @@ pub fn gen_svg(
) -> Document { ) -> Document {
let local_timestamp = Local::now(); let local_timestamp = Local::now();
let utc_hour = local_timestamp.with_timezone(&Utc).time().hour(); let utc_hour = local_timestamp.with_timezone(&Utc).time().hour();
let local_hour = local_timestamp.time().hour(); let (local_hour, local_minute, local_second) = get_hms(DayPart::LocalNow);
let local_minute = local_timestamp.time().minute();
let local_second = local_timestamp.time().second();
let unixtime = suncalc::Timestamp(local_timestamp.timestamp_millis()); let unixtime = suncalc::Timestamp(local_timestamp.timestamp_millis());
let utc_offset = local_timestamp.offset().local_minus_utc(); let utc_offset = local_timestamp.offset().local_minus_utc();