diff options
Diffstat (limited to 'src/rtc.rs')
| -rw-r--r-- | src/rtc.rs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/rtc.rs b/src/rtc.rs index afd46610e..facb9cf8c 100644 --- a/src/rtc.rs +++ b/src/rtc.rs | |||
| @@ -109,18 +109,29 @@ pub fn convert_seconds_to_datetime(seconds: u32) -> RtcDateTime { | |||
| 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.is_multiple_of(4) { | 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 | ||
