1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use error::*;
use schedule::{Ordinal, OrdinalSet};
use std::borrow::Cow;
use time_unit::TimeUnitField;
#[derive(Clone)]
pub struct DaysOfWeek(OrdinalSet);
impl TimeUnitField for DaysOfWeek {
fn from_ordinal_set(ordinal_set: OrdinalSet) -> Self {
DaysOfWeek(ordinal_set)
}
fn name() -> Cow<'static, str> {
Cow::from("Days of Week")
}
fn inclusive_min() -> Ordinal {
1
}
fn inclusive_max() -> Ordinal {
7
}
fn ordinal_from_name(name: &str) -> Result<Ordinal> {
let ordinal = match name.to_lowercase().as_ref() {
"sun" | "sunday" => 1,
"mon" | "monday" => 2,
"tue" | "tues" | "tuesday" => 3,
"wed" | "wednesday" => 4,
"thu" | "thurs" | "thursday" => 5,
"fri" | "friday" => 6,
"sat" | "saturday" => 7,
_ => bail!(ErrorKind::Expression(format!(
"'{}' is not a valid day of the week.",
name
))),
};
Ok(ordinal)
}
fn ordinals(&self) -> &OrdinalSet {
&self.0
}
}