x86: don't panic when RTC returns invalid values
This commit is contained in:
parent
ca7564a70b
commit
3e5f3fc6cd
@ -179,15 +179,15 @@ impl Rtc {
|
||||
impl DateTime {
|
||||
pub fn to_seconds(self) -> u64 {
|
||||
let date = chrono::NaiveDate::from_ymd_opt(
|
||||
2000 + self.year as i32,
|
||||
self.month as u32,
|
||||
self.day_of_month as u32,
|
||||
2000 + self.year.max(100) as i32,
|
||||
self.month.clamp(1, 12) as u32,
|
||||
self.day_of_month.clamp(1, 31) as u32,
|
||||
)
|
||||
.unwrap();
|
||||
let time = chrono::NaiveTime::from_hms_opt(
|
||||
self.hours as u32,
|
||||
self.minutes as u32,
|
||||
self.seconds as u32,
|
||||
self.hours.clamp(0, 23) as u32,
|
||||
self.minutes.clamp(0, 59) as u32,
|
||||
self.seconds.clamp(0, 59) as u32,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user