cron/time_unit/
years.rs

1use crate::ordinal::{Ordinal, OrdinalSet};
2use crate::time_unit::TimeUnitField;
3use once_cell::sync::Lazy;
4use std::borrow::Cow;
5
6static ALL: Lazy<OrdinalSet> = Lazy::new(Years::supported_ordinals);
7
8#[derive(Clone, Debug, Eq)]
9pub struct Years {
10    ordinals: Option<OrdinalSet>,
11}
12
13impl TimeUnitField for Years {
14    fn from_optional_ordinal_set(ordinal_set: Option<OrdinalSet>) -> Self {
15        Years {
16            ordinals: ordinal_set,
17        }
18    }
19    fn name() -> Cow<'static, str> {
20        Cow::from("Years")
21    }
22
23    // TODO: Using the default impl, this will make a set w/100+ items each time "*" is used.
24    // This is obviously suboptimal.
25    fn inclusive_min() -> Ordinal {
26        1970
27    }
28    fn inclusive_max() -> Ordinal {
29        2100
30    }
31    fn ordinals(&self) -> &OrdinalSet {
32        match &self.ordinals {
33            Some(ordinal_set) => ordinal_set,
34            None => &ALL,
35        }
36    }
37}
38
39impl PartialEq for Years {
40    fn eq(&self, other: &Years) -> bool {
41        self.ordinals() == other.ordinals()
42    }
43}