[Refactor] Move UTC offset calculation to the clock module

This commit is contained in:
Gergely Polonkai 2022-05-24 10:43:29 +02:00
parent eecd5c2938
commit 8968507d29
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
2 changed files with 6 additions and 3 deletions

View File

@ -94,3 +94,7 @@ pub fn get_hms(config: &Option<Config>, which: DayPart) -> (u8, u8, u8) {
(hours as u8, minutes as u8, seconds as u8) (hours as u8, minutes as u8, seconds as u8)
} }
pub fn get_utc_offset() -> i32 {
Local::now().offset().local_minus_utc()
}

View File

@ -1,6 +1,5 @@
use std::fmt; use std::fmt;
use chrono::prelude::Local;
use rctree::Node; use rctree::Node;
use svg::{ use svg::{
node::{ node::{
@ -14,7 +13,7 @@ use svg::{
}; };
use usvg::Tree; use usvg::Tree;
use crate::clock::{get_hms, get_moon_phase, get_seconds_since_midnight, DayPart}; use crate::clock::{get_hms, get_moon_phase, get_seconds_since_midnight, get_utc_offset, DayPart};
use crate::config::Config; use crate::config::Config;
const HOUR_NAMES: [&str; 24] = [ const HOUR_NAMES: [&str; 24] = [
@ -341,7 +340,7 @@ pub fn gen_svg(
let (utc_hour, _, _) = get_hms(config, DayPart::UtcNow); let (utc_hour, _, _) = get_hms(config, DayPart::UtcNow);
let (local_hour, local_minute, local_second) = get_hms(config, DayPart::LocalNow); let (local_hour, local_minute, local_second) = get_hms(config, DayPart::LocalNow);
let utc_offset = Local::now().offset().local_minus_utc(); let utc_offset = get_utc_offset();
let local_time = get_seconds_since_midnight(config, DayPart::LocalNow); let local_time = get_seconds_since_midnight(config, DayPart::LocalNow);
let utc_rotation = seconds_to_degrees(utc_offset); let utc_rotation = seconds_to_degrees(utc_offset);
let moon_radius = IMAGE_WIDTH as f32 * 0.071428571; let moon_radius = IMAGE_WIDTH as f32 * 0.071428571;