use chrono::NaiveDate; use std::vec::Vec; use std::default::Default; use std::string::String; #[derive(Clone)] pub struct Event { pub text: String, pub begin: NaiveDate, pub end: NaiveDate, } //impl Clone for Event { // fn clone(&self) -> Self { // Event { // text: self.text.clone(), // begin: self.begin, // end: self.end, // } // } //} // impl Event { fn is_in_day(&self, day: NaiveDate) -> bool { day >= self.begin && day <= self.end } } pub struct EventsCollection { events: Vec, } impl EventsCollection { pub fn new() -> Self { EventsCollection { // TODO: hard-coded events events: vec![ Event { text: String::from("pentecoste"), begin: NaiveDate::from_ymd_opt(2023, 05, 30).unwrap(), end: NaiveDate::from_ymd_opt(2023, 06, 09).unwrap(), }, Event { text: String::from("estate"), begin: NaiveDate::from_ymd_opt(2023, 07, 31).unwrap(), end: NaiveDate::from_ymd_opt(2023, 09, 11).unwrap(), }, ], } } pub fn is_any_in_day(&self, day: NaiveDate) -> Option { for ev_day in &self.events { if ev_day.is_in_day(day) { return Some(ev_day.clone()); } } None } pub fn for_day(&self, day: NaiveDate) -> Vec { let mut events_in_day = Vec::new(); for ev_day in &self.events { if ev_day.is_in_day(day) { events_in_day.push(ev_day.clone()); } } events_in_day } } impl Default for EventsCollection { fn default() -> EventsCollection { EventsCollection::new() } }