practical_astronomy_rust/
util.rs1pub fn is_leap_year(input_year: u32) -> bool {
9 let year = input_year as f64;
10
11 if year % 4.0 == 0.0 {
12 if year % 100.0 == 0.0 {
13 return if year % 400.0 == 0.0 { true } else { false };
14 } else {
15 return true;
16 }
17 } else {
18 return false;
19 }
20}
21
22pub fn round_f64(input_value: f64, places: usize) -> f64 {
24 return format!("{:.width$}", input_value, width = places)
25 .parse::<f64>()
26 .unwrap();
27}
28
29pub fn get_local_hour_from_ut(
31 input_hour: f64,
32 is_daylight_saving: bool,
33 zone_correction_hours: i32,
34) -> f64 {
35 let adjustment_value: f64 = if is_daylight_saving {
36 (zone_correction_hours as f64) - 1.0
37 } else {
38 zone_correction_hours as f64
39 };
40
41 let local_hour: f64 = input_hour - adjustment_value;
42
43 return local_hour;
44}