refactoring

This commit is contained in:
Lennart
2024-03-29 14:06:33 +01:00
parent 93d22939a4
commit 29adbadfb4
3 changed files with 8 additions and 8 deletions

View File

@@ -82,7 +82,7 @@ impl Event {
pub fn get_first_occurence(&self) -> Result<NaiveDateTime> {
// This is safe since we enforce the event's existance in the constructor
let event = self.cal.events.get(0).unwrap();
let event = self.cal.events.first().unwrap();
let dtstart = event
.get_property("DTSTART")
.ok_or(anyhow!("DTSTART property missing!"))?
@@ -94,7 +94,7 @@ impl Event {
pub fn get_last_occurence(&self) -> Result<NaiveDateTime> {
// This is safe since we enforce the event's existance in the constructor
let event = self.cal.events.get(0).unwrap();
let event = self.cal.events.first().unwrap();
if event.get_property("RRULE").is_some() {
// TODO: understand recurrence rules

View File

@@ -12,19 +12,19 @@ pub fn parse_duration(string: &str) -> Result<Duration> {
let mut duration = Duration::zero();
if let Some(weeks) = captures.name("W") {
duration = duration + Duration::weeks(weeks.as_str().parse()?);
duration += Duration::weeks(weeks.as_str().parse()?);
}
if let Some(days) = captures.name("D") {
duration = duration + Duration::days(days.as_str().parse()?);
duration += Duration::days(days.as_str().parse()?);
}
if let Some(hours) = captures.name("H") {
duration = duration + Duration::hours(hours.as_str().parse()?);
duration += Duration::hours(hours.as_str().parse()?);
}
if let Some(minutes) = captures.name("M") {
duration = duration + Duration::minutes(minutes.as_str().parse()?);
duration += Duration::minutes(minutes.as_str().parse()?);
}
if let Some(seconds) = captures.name("S") {
duration = duration + Duration::seconds(seconds.as_str().parse()?);
duration += Duration::seconds(seconds.as_str().parse()?);
}
if let Some(sign) = captures.name("sign") {
if sign.as_str() == "-" {

View File

@@ -80,7 +80,7 @@ impl CalendarStore for TomlCalendarStore {
}
async fn upsert_event(&mut self, cid: String, uid: String, ics: String) -> Result<()> {
let events = self.events.entry(cid).or_insert(HashMap::new());
let events = self.events.entry(cid).or_default();
events.insert(uid.clone(), Event::from_ics(uid, ics)?);
self.save().await.unwrap();
Ok(())