Generate error when century bit is set in month method.

Paul Bender 2025-10-10 18:33:41 -07:00
parent 459dfa9200
commit 57ecefccc3
2 changed files with 7 additions and 8 deletions

View File

@ -93,8 +93,13 @@ where
fn month(&mut self) -> Result<u8, Self::Error> {
let data = self.iface.read_register(Register::MONTH)?;
let value = data & !BitFlags::CENTURY;
Ok(packed_bcd_to_decimal(value))
let century = data & BitFlags::CENTURY;
if century != 0 {
return Err(Error::InvalidDeviceCentury);
}
Ok(packed_bcd_to_decimal(data))
}
fn year(&mut self) -> Result<u16, Self::Error> {

View File

@ -185,12 +185,6 @@ mod month {
get_param_test!(get, month, MONTH, 1, 1);
read_set_param_test!(set, set_month, MONTH, 12, 0b0000_0010, 0b0001_0010);
set_invalid_param_range_test!(invalid, set_month, 0, 13);
mod keeps_century {
use super::*;
get_param_test!(get, month, MONTH, 12, 0b1001_0010);
read_set_param_test!(set, set_month, MONTH, 12, 0b1000_0010, 0b1001_0010);
}
}
mod year {