Skip to content

Commit

Permalink
fix(calendar): CalendarEventStore panic (#822)
Browse files Browse the repository at this point in the history
`CalendarEventStore::today()` panics if the system's UTC offset cannot
be determined. In this circumstance, it's better to use `now_utc`
instead.
  • Loading branch information
lxl66566 authored Jan 15, 2024
1 parent 5131c81 commit c959bd2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/widgets/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ impl CalendarEventStore {
/// your own type that implements [`Into<Style>`]).
pub fn today<S: Into<Style>>(style: S) -> Self {
let mut res = Self::default();
res.add(OffsetDateTime::now_local().unwrap().date(), style.into());
res.add(
OffsetDateTime::now_local()
.unwrap_or(OffsetDateTime::now_utc())
.date(),
style.into(),
);
res
}

Expand Down Expand Up @@ -260,4 +265,9 @@ mod tests {
"Date added to styler should return the provided style"
);
}

#[test]
fn test_today() {
CalendarEventStore::today(Style::default());
}
}

0 comments on commit c959bd2

Please sign in to comment.