mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 14:02:29 +00:00
refactoring
This commit is contained in:
@@ -82,7 +82,7 @@ impl Event {
|
|||||||
|
|
||||||
pub fn get_first_occurence(&self) -> Result<NaiveDateTime> {
|
pub fn get_first_occurence(&self) -> Result<NaiveDateTime> {
|
||||||
// This is safe since we enforce the event's existance in the constructor
|
// 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
|
let dtstart = event
|
||||||
.get_property("DTSTART")
|
.get_property("DTSTART")
|
||||||
.ok_or(anyhow!("DTSTART property missing!"))?
|
.ok_or(anyhow!("DTSTART property missing!"))?
|
||||||
@@ -94,7 +94,7 @@ impl Event {
|
|||||||
|
|
||||||
pub fn get_last_occurence(&self) -> Result<NaiveDateTime> {
|
pub fn get_last_occurence(&self) -> Result<NaiveDateTime> {
|
||||||
// This is safe since we enforce the event's existance in the constructor
|
// 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() {
|
if event.get_property("RRULE").is_some() {
|
||||||
// TODO: understand recurrence rules
|
// TODO: understand recurrence rules
|
||||||
|
|||||||
@@ -12,19 +12,19 @@ pub fn parse_duration(string: &str) -> Result<Duration> {
|
|||||||
|
|
||||||
let mut duration = Duration::zero();
|
let mut duration = Duration::zero();
|
||||||
if let Some(weeks) = captures.name("W") {
|
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") {
|
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") {
|
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") {
|
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") {
|
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 let Some(sign) = captures.name("sign") {
|
||||||
if sign.as_str() == "-" {
|
if sign.as_str() == "-" {
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ impl CalendarStore for TomlCalendarStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn upsert_event(&mut self, cid: String, uid: String, ics: String) -> Result<()> {
|
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)?);
|
events.insert(uid.clone(), Event::from_ics(uid, ics)?);
|
||||||
self.save().await.unwrap();
|
self.save().await.unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user