From 4dd0bea78b888031a1bb529de84a93d0ed7ee195 Mon Sep 17 00:00:00 2001 From: daladim Date: Fri, 26 Feb 2021 17:55:57 +0100 Subject: [PATCH] get_tasks returns a HashMap --- src/calendar.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/calendar.rs b/src/calendar.rs index bddb080..143de29 100644 --- a/src/calendar.rs +++ b/src/calendar.rs @@ -1,8 +1,10 @@ use std::convert::TryFrom; use std::error::Error; +use std::collections::HashMap; use url::Url; use serde::{Deserialize, Serialize}; +use chrono::{DateTime, Utc}; use crate::task::Task; use crate::task::TaskId; @@ -91,7 +93,7 @@ impl Calendar { /// Returns the list of tasks that this calendar contains /// Pass a `completed` flag to filter only the completed (or non-completed) tasks - pub fn get_tasks(&self, completed: Option) -> Vec<&Task> { + pub fn get_tasks(&self, completed: Option) -> HashMap { self.get_tasks_modified_since(None, completed) } @@ -108,9 +110,20 @@ impl Calendar { /// Returns the tasks that have been last-modified after `since` /// Pass a `completed` flag to filter only the completed (or non-completed) tasks - fn get_tasks_modified_since(&self, _since: Option, _completed: Option) -> Vec<&Task> { - self.tasks - .iter() - .collect() + pub fn get_tasks_modified_since(&self, since: Option>, _completed: Option) -> HashMap { + let mut map = HashMap::new(); + + for task in &self.tasks { + match since { + None => (), + Some(since) => if task.last_modified() < since { + continue; + }, + } + + map.insert(task.id().clone(), task); + } + + map } }