cron/time_unit/
days_of_month.rs

1use crate::ordinal::{Ordinal, OrdinalSet, Pattern, OrdinalList};
2use crate::time_unit::TimeUnitField;
3use std::borrow::Cow;
4use once_cell::sync::Lazy;
5
6static ALL: Lazy<OrdinalSet> = Lazy::new(|| { DaysOfMonth::supported_ordinals() });
7
8#[derive(Clone, Debug, Eq)]
9pub struct DaysOfMonth{
10    ordinals: Option<OrdinalSet>,
11    pattern: Pattern,
12    ordinal_list: OrdinalList
13}
14
15impl TimeUnitField for DaysOfMonth {
16    fn from_optional_ordinal_set(ordinal_set: Option<OrdinalSet>, pattern: Pattern, ordinal_list: OrdinalList) -> Self {
17        DaysOfMonth {
18            ordinals: ordinal_set,
19            pattern,
20            ordinal_list,
21        }
22    }
23    fn name() -> Cow<'static, str> {
24        Cow::from("Days of Month")
25    }
26    fn inclusive_min() -> Ordinal {
27        1
28    }
29    fn inclusive_max() -> Ordinal {
30        31
31    }
32    fn ordinals(&self) -> &OrdinalSet {
33        match &self.ordinals {
34            Some(ordinal_set) => ordinal_set,
35            None => &ALL
36        }
37    }
38    fn ordinal_list(&self) -> &OrdinalList {
39        &self.ordinal_list
40    }
41    fn matching_pattern(&self) -> &str {
42        &self.pattern
43    }
44}
45
46impl PartialEq for DaysOfMonth {
47    fn eq(&self, other: &DaysOfMonth) -> bool {
48        self.ordinals() == other.ordinals()
49    }
50}