diff options
| author | James Munns <[email protected]> | 2025-11-13 18:11:22 +0100 |
|---|---|---|
| committer | James Munns <[email protected]> | 2025-11-13 18:11:22 +0100 |
| commit | 0f8e7650b937aa5d4accef3fdf01047afe099df3 (patch) | |
| tree | f14a38f1ce61d8749224304c6c84bf3673cb3b01 /src/rtc.rs | |
| parent | dd7a90eb51197fae6ef6c6b7beae977a9143e268 (diff) | |
| parent | 7480db25d5cc1866a3e037bfb89f990d9847bd10 (diff) | |
Merge remote-tracking branch 'origin/main' into james/impl-clocks
Diffstat (limited to 'src/rtc.rs')
| -rw-r--r-- | src/rtc.rs | 27 |
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 | ||
