1
use crate::common::{CalendarDateTime, OffsetWeekday, RecurFreq, Weekday};
2

            
3
#[derive(Debug, PartialEq)]
4
pub enum RecurRulePart {
5
    Freq(RecurFreq),
6
    Until(CalendarDateTime),
7
    Count(u64),
8
    Interval(u64),
9
    BySecList(Vec<u8>),
10
    ByMinute(Vec<u8>),
11
    ByHour(Vec<u8>),
12
    ByDay(Vec<OffsetWeekday>),
13
    ByMonthDay(Vec<i8>),
14
    ByYearDay(Vec<i16>),
15
    ByWeekNumber(Vec<i8>),
16
    ByMonth(Vec<time::Month>),
17
    BySetPos(Vec<i16>),
18
    WeekStart(Weekday),
19
}
20

            
21
#[derive(Debug, PartialEq)]
22
pub struct RecurrenceRule {
23
    pub parts: Vec<RecurRulePart>,
24
}
25

            
26
impl RecurrenceRule {
27
62
    pub fn new(freq: RecurFreq) -> Self {
28
62
        RecurrenceRule {
29
62
            parts: vec![RecurRulePart::Freq(freq)],
30
62
        }
31
62
    }
32

            
33
204
    pub(crate) fn empty_with_capacity(capacity: usize) -> Self {
34
204
        RecurrenceRule {
35
204
            parts: Vec::with_capacity(capacity),
36
204
        }
37
204
    }
38

            
39
204
    pub(crate) fn set_freq(mut self, freq: RecurFreq) -> Self {
40
204
        self.parts.push(RecurRulePart::Freq(freq));
41
204
        self
42
204
    }
43

            
44
124
    pub fn set_until(mut self, date_time: CalendarDateTime) -> Self {
45
124
        self.parts.push(RecurRulePart::Until(date_time));
46
124
        self
47
124
    }
48

            
49
100
    pub fn set_count(mut self, count: u64) -> Self {
50
100
        self.parts.push(RecurRulePart::Count(count));
51
100
        self
52
100
    }
53

            
54
100
    pub fn set_interval(mut self, interval: u64) -> Self {
55
100
        self.parts.push(RecurRulePart::Interval(interval));
56
100
        self
57
100
    }
58

            
59
102
    pub fn set_by_second(mut self, by_second: Vec<u8>) -> Self {
60
102
        self.parts.push(RecurRulePart::BySecList(by_second));
61
102
        self
62
102
    }
63

            
64
102
    pub fn set_by_minute(mut self, by_minute: Vec<u8>) -> Self {
65
102
        self.parts.push(RecurRulePart::ByMinute(by_minute));
66
102
        self
67
102
    }
68

            
69
104
    pub fn set_by_hour(mut self, by_hour: Vec<u8>) -> Self {
70
104
        self.parts.push(RecurRulePart::ByHour(by_hour));
71
104
        self
72
104
    }
73

            
74
164
    pub fn set_by_day(mut self, by_day: Vec<OffsetWeekday>) -> Self {
75
164
        self.parts.push(RecurRulePart::ByDay(by_day));
76
164
        self
77
164
    }
78

            
79
102
    pub fn set_by_month_day(mut self, by_month_day: Vec<i8>) -> Self {
80
102
        self.parts.push(RecurRulePart::ByMonthDay(by_month_day));
81
102
        self
82
102
    }
83

            
84
106
    pub fn set_by_year_day(mut self, by_year_day: Vec<i16>) -> Self {
85
106
        self.parts.push(RecurRulePart::ByYearDay(by_year_day));
86
106
        self
87
106
    }
88

            
89
106
    pub fn set_by_week_number(mut self, by_week_number: Vec<i8>) -> Self {
90
106
        self.parts.push(RecurRulePart::ByWeekNumber(by_week_number));
91
106
        self
92
106
    }
93

            
94
126
    pub fn set_by_month(mut self, by_month: Vec<time::Month>) -> Self {
95
126
        self.parts.push(RecurRulePart::ByMonth(by_month));
96
126
        self
97
126
    }
98

            
99
104
    pub fn set_by_set_pos(mut self, by_set_pos: Vec<i16>) -> Self {
100
104
        self.parts.push(RecurRulePart::BySetPos(by_set_pos));
101
104
        self
102
104
    }
103

            
104
106
    pub fn set_week_start(mut self, week_start: Weekday) -> Self {
105
106
        self.parts.push(RecurRulePart::WeekStart(week_start));
106
106
        self
107
106
    }
108
}