dateless/event/period/
mod.rs1use chrono::{Date, DateTime, Utc};
2use std::fmt::Debug;
3
4#[cfg(feature = "serde_support")]
5use serde::{Deserialize, Serialize};
6
7#[cfg_attr(feature = "serde_support", typetag::serde(tag = "type"))]
8pub trait Period: Debug + Send {
9 fn contains(&self, date: Date<Utc>) -> bool;
10 fn get_date_time_start(&self) -> DateTime<Utc>;
11 fn starts_before(&self, date: Date<Utc>) -> bool;
12 fn with_new_start(&self, date: Date<Utc>) -> Box<dyn Period>;
13 fn cloned(&self) -> Box<dyn Period>;
15 fn as_weekdays(&self) -> (u32, u32);
16 fn as_days_of_month(&self) -> (u32, u32);
17 fn as_months(&self) -> (u32, u32);
18 fn with_new_month(&self, month: u32) -> Date<Utc>;
19}
20
21#[derive(Debug)]
22#[cfg_attr(feature = "serde_support", derive(Serialize, Deserialize))]
23pub struct PeriodDef(pub Box<dyn Period>);
24
25impl Default for PeriodDef {
26 fn default() -> Self {
27 Self(Box::new(WholeDays(
28 Utc::today(),
29 Utc::today() + chrono::Duration::days(1),
30 )))
31 }
32}
33
34mod start_end;
35mod whole_days;
36
37pub use start_end::*;
38pub use whole_days::*;