[Refactor] Move UTC hour calculation to the clock module
This commit is contained in:
parent
d56c6ef087
commit
b485b01c2f
10
src/clock.rs
10
src/clock.rs
@ -1,7 +1,11 @@
|
|||||||
use chrono::{prelude::Local, Timelike};
|
use chrono::{
|
||||||
|
prelude::{Local, Utc},
|
||||||
|
Timelike,
|
||||||
|
};
|
||||||
|
|
||||||
pub enum DayPart {
|
pub enum DayPart {
|
||||||
LocalNow,
|
LocalNow,
|
||||||
|
UtcNow,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_moon_phase() -> f32 {
|
pub fn get_moon_phase() -> f32 {
|
||||||
@ -17,6 +21,10 @@ pub fn get_seconds_since_midnight(which: DayPart) -> i32 {
|
|||||||
|
|
||||||
let seconds = match which {
|
let seconds = match which {
|
||||||
DayPart::LocalNow => local_timestamp.time().num_seconds_from_midnight(),
|
DayPart::LocalNow => local_timestamp.time().num_seconds_from_midnight(),
|
||||||
|
DayPart::UtcNow => local_timestamp
|
||||||
|
.with_timezone(&Utc)
|
||||||
|
.time()
|
||||||
|
.num_seconds_from_midnight(),
|
||||||
};
|
};
|
||||||
|
|
||||||
seconds as i32
|
seconds as i32
|
||||||
|
@ -342,7 +342,7 @@ pub fn gen_svg(
|
|||||||
hour_name_path_cache: &[(PathData, PathData); 24],
|
hour_name_path_cache: &[(PathData, PathData); 24],
|
||||||
) -> 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, _, _) = get_hms(DayPart::UtcNow);
|
||||||
let (local_hour, local_minute, local_second) = get_hms(DayPart::LocalNow);
|
let (local_hour, local_minute, local_second) = get_hms(DayPart::LocalNow);
|
||||||
let unixtime = suncalc::Timestamp(local_timestamp.timestamp_millis());
|
let unixtime = suncalc::Timestamp(local_timestamp.timestamp_millis());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user