51 lines
1.1 KiB
Rust
51 lines
1.1 KiB
Rust
use chrono::NaiveDate;
|
|
use std::vec::Vec;
|
|
use std::default::Default;
|
|
|
|
pub struct Event {
|
|
begin: NaiveDate,
|
|
end: NaiveDate,
|
|
}
|
|
|
|
impl Event {
|
|
fn is_in_day(&self, day: NaiveDate) -> bool {
|
|
day >= self.begin && day <= self.end
|
|
}
|
|
}
|
|
|
|
pub struct EventsCollection {
|
|
events: Vec<Event>,
|
|
}
|
|
|
|
impl EventsCollection {
|
|
pub fn new() -> Self {
|
|
EventsCollection {
|
|
// TODO: hard-coded events
|
|
events: vec![
|
|
Event {
|
|
begin: NaiveDate::from_ymd_opt(2023, 01, 15).unwrap(),
|
|
end: NaiveDate::from_ymd_opt(2023, 01, 16).unwrap(),
|
|
},
|
|
Event {
|
|
begin: NaiveDate::from_ymd_opt(2023, 01, 16).unwrap(),
|
|
end: NaiveDate::from_ymd_opt(2023, 01, 17).unwrap(),
|
|
},
|
|
],
|
|
}
|
|
}
|
|
|
|
pub fn is_any_in_day(&self, day: NaiveDate) -> bool {
|
|
for ev_day in &self.events {
|
|
if ev_day.is_in_day(day) {
|
|
return true;
|
|
}
|
|
}
|
|
false
|
|
}
|
|
}
|
|
|
|
impl Default for EventsCollection {
|
|
fn default() -> EventsCollection {
|
|
EventsCollection::new()
|
|
}
|
|
} |