mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 14:02:29 +00:00
Implement occurence getters for calendar object
This commit is contained in:
@@ -25,7 +25,7 @@ impl EventObject {
|
||||
} else {
|
||||
return Ok(None);
|
||||
};
|
||||
Ok(Some(CalDateTime::from_str(&dtstart)?))
|
||||
Ok(Some(CalDateTime::from_str(dtstart)?))
|
||||
}
|
||||
|
||||
pub fn get_last_occurence(&self) -> Result<Option<CalDateTime>, Error> {
|
||||
@@ -39,7 +39,7 @@ impl EventObject {
|
||||
value: Some(dtend), ..
|
||||
}) = self.event.get_property("DTEND")
|
||||
{
|
||||
return Ok(Some(CalDateTime::from_str(&dtend)?));
|
||||
return Ok(Some(CalDateTime::from_str(dtend)?));
|
||||
};
|
||||
|
||||
let duration = if let Some(Property {
|
||||
@@ -47,12 +47,12 @@ impl EventObject {
|
||||
..
|
||||
}) = self.event.get_property("DURATION")
|
||||
{
|
||||
parse_duration(&duration)?
|
||||
parse_duration(duration)?
|
||||
} else {
|
||||
Duration::days(1)
|
||||
};
|
||||
|
||||
let first_occurence = self.get_first_occurence()?;
|
||||
return Ok(first_occurence.map(|first_occurence| first_occurence + duration));
|
||||
Ok(first_occurence.map(|first_occurence| first_occurence + duration))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::{event::EventObject, todo::TodoObject};
|
||||
use crate::Error;
|
||||
use crate::{timestamp::CalDateTime, Error};
|
||||
use anyhow::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
@@ -126,4 +126,18 @@ impl CalendarObject {
|
||||
CalendarObjectComponent::Event(_) => "VEVENT",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_first_occurence(&self) -> Result<Option<CalDateTime>, Error> {
|
||||
match &self.data {
|
||||
CalendarObjectComponent::Event(event) => event.get_first_occurence(),
|
||||
_ => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_last_occurence(&self) -> Result<Option<CalDateTime>, Error> {
|
||||
match &self.data {
|
||||
CalendarObjectComponent::Event(event) => event.get_last_occurence(),
|
||||
_ => Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user