[Refactor] Move local time calculation to the clock module
This commit is contained in:
		
							
								
								
									
										11
									
								
								src/clock.rs
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/clock.rs
									
									
									
									
									
								
							| @@ -21,3 +21,14 @@ pub fn get_seconds_since_midnight(which: DayPart) -> 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) | ||||
| } | ||||
|   | ||||
| @@ -17,7 +17,7 @@ use svg::{ | ||||
| }; | ||||
| 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; | ||||
|  | ||||
| const HOUR_NAMES: [&str; 24] = [ | ||||
| @@ -343,9 +343,7 @@ pub fn gen_svg( | ||||
| ) -> Document { | ||||
|     let local_timestamp = Local::now(); | ||||
|     let utc_hour = local_timestamp.with_timezone(&Utc).time().hour(); | ||||
|     let local_hour = local_timestamp.time().hour(); | ||||
|     let local_minute = local_timestamp.time().minute(); | ||||
|     let local_second = local_timestamp.time().second(); | ||||
|     let (local_hour, local_minute, local_second) = get_hms(DayPart::LocalNow); | ||||
|     let unixtime = suncalc::Timestamp(local_timestamp.timestamp_millis()); | ||||
|  | ||||
|     let utc_offset = local_timestamp.offset().local_minus_utc(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user