aboutsummaryrefslogtreecommitdiff
path: root/src/rtc.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/rtc.rs')
-rw-r--r--src/rtc.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/rtc.rs b/src/rtc.rs
index d62da1f0a..facb9cf8c 100644
--- a/src/rtc.rs
+++ b/src/rtc.rs
@@ -102,25 +102,36 @@ pub fn convert_seconds_to_datetime(seconds: u32) -> RtcDateTime {
102 days -= days_in_year; 102 days -= days_in_year;
103 year += 1; 103 year += 1;
104 104
105 days_in_year = if year % 4 == 0 { 105 days_in_year = if year.is_multiple_of(4) {
106 DAYS_IN_A_YEAR + 1 106 DAYS_IN_A_YEAR + 1
107 } else { 107 } else {
108 DAYS_IN_A_YEAR 108 DAYS_IN_A_YEAR
109 }; 109 };
110 } 110 }
111 111
112 let mut days_per_month = [0u8, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 112 let days_per_month = [
113 if year % 4 == 0 { 113 31,
114 days_per_month[2] = 29; 114 if year.is_multiple_of(4) { 29 } else { 28 },
115 } 115 31,
116 30,
117 31,
118 30,
119 31,
120 31,
121 30,
122 31,
123 30,
124 31,
125 ];
116 126
117 let mut month = 1; 127 let mut month = 1;
118 for m in 1..=12 { 128 for (m, month_days) in days_per_month.iter().enumerate() {
119 if days <= days_per_month[m] as u32 { 129 let m = m + 1;
130 if days <= *month_days as u32 {
120 month = m; 131 month = m;
121 break; 132 break;
122 } else { 133 } else {
123 days -= days_per_month[m] as u32; 134 days -= *month_days as u32;
124 } 135 }
125 } 136 }
126 137