diff options
| author | sodo <[email protected]> | 2024-01-02 01:37:00 +0900 |
|---|---|---|
| committer | sodo <[email protected]> | 2024-01-02 13:34:22 +0900 |
| commit | 6ee153a3e2eec284c0d9d87f31801265c0604f74 (patch) | |
| tree | 8b801cbd15f9ad5052d5942c731e75736dc9d7eb /embassy-stm32/src/rtc/datetime.rs | |
| parent | b7cd7952c890f585ff876c622482534e5d58d4a4 (diff) | |
| parent | 0be9b0599aaf2e425d76ec7852ff4b3535defddf (diff) | |
Merge remote-tracking branch 'origin'
Diffstat (limited to 'embassy-stm32/src/rtc/datetime.rs')
| -rw-r--r-- | embassy-stm32/src/rtc/datetime.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/embassy-stm32/src/rtc/datetime.rs b/embassy-stm32/src/rtc/datetime.rs index f4e86dd87..ef92fa4bb 100644 --- a/embassy-stm32/src/rtc/datetime.rs +++ b/embassy-stm32/src/rtc/datetime.rs | |||
| @@ -104,45 +104,51 @@ pub struct DateTime { | |||
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | impl DateTime { | 106 | impl DateTime { |
| 107 | /// Get the year (0..=4095) | ||
| 107 | pub const fn year(&self) -> u16 { | 108 | pub const fn year(&self) -> u16 { |
| 108 | self.year | 109 | self.year |
| 109 | } | 110 | } |
| 110 | 111 | ||
| 112 | /// Get the month (1..=12, 1 is January) | ||
| 111 | pub const fn month(&self) -> u8 { | 113 | pub const fn month(&self) -> u8 { |
| 112 | self.month | 114 | self.month |
| 113 | } | 115 | } |
| 114 | 116 | ||
| 117 | /// Get the day (1..=31) | ||
| 115 | pub const fn day(&self) -> u8 { | 118 | pub const fn day(&self) -> u8 { |
| 116 | self.day | 119 | self.day |
| 117 | } | 120 | } |
| 118 | 121 | ||
| 122 | /// Get the day of week | ||
| 119 | pub const fn day_of_week(&self) -> DayOfWeek { | 123 | pub const fn day_of_week(&self) -> DayOfWeek { |
| 120 | self.day_of_week | 124 | self.day_of_week |
| 121 | } | 125 | } |
| 122 | 126 | ||
| 127 | /// Get the hour (0..=23) | ||
| 123 | pub const fn hour(&self) -> u8 { | 128 | pub const fn hour(&self) -> u8 { |
| 124 | self.hour | 129 | self.hour |
| 125 | } | 130 | } |
| 126 | 131 | ||
| 132 | /// Get the minute (0..=59) | ||
| 127 | pub const fn minute(&self) -> u8 { | 133 | pub const fn minute(&self) -> u8 { |
| 128 | self.minute | 134 | self.minute |
| 129 | } | 135 | } |
| 130 | 136 | ||
| 137 | /// Get the second (0..=59) | ||
| 131 | pub const fn second(&self) -> u8 { | 138 | pub const fn second(&self) -> u8 { |
| 132 | self.second | 139 | self.second |
| 133 | } | 140 | } |
| 134 | 141 | ||
| 142 | /// Create a new DateTime with the given information. | ||
| 135 | pub fn from( | 143 | pub fn from( |
| 136 | year: u16, | 144 | year: u16, |
| 137 | month: u8, | 145 | month: u8, |
| 138 | day: u8, | 146 | day: u8, |
| 139 | day_of_week: u8, | 147 | day_of_week: DayOfWeek, |
| 140 | hour: u8, | 148 | hour: u8, |
| 141 | minute: u8, | 149 | minute: u8, |
| 142 | second: u8, | 150 | second: u8, |
| 143 | ) -> Result<Self, Error> { | 151 | ) -> Result<Self, Error> { |
| 144 | let day_of_week = day_of_week_from_u8(day_of_week)?; | ||
| 145 | |||
| 146 | if year > 4095 { | 152 | if year > 4095 { |
| 147 | Err(Error::InvalidYear) | 153 | Err(Error::InvalidYear) |
| 148 | } else if month < 1 || month > 12 { | 154 | } else if month < 1 || month > 12 { |
