summaryrefslogtreecommitdiff
path: root/src/rrule.rs
blob: ab13a9cdd5c44af65181f594bb26e3d63b12e070 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::iter::*;
use crate::iter_set::iter_v2;
use crate::options::*;
use chrono::prelude::*;
use chrono_tz::{Tz, UTC};

#[derive(Clone, Debug)]
pub struct RRule {
    cache: bool,
    pub options: ParsedOptions,
}

impl RRule {
    pub fn new(options: ParsedOptions) -> Self {
        Self {
            options,
            cache: true,
        }
    }

    pub fn disable_cache(&mut self) {
        self.cache = false;
    }

    pub fn all(&mut self) -> Vec<DateTime<Tz>> {
        let iter_args = IterArgs {
            inc: true,
            before: UTC.ymd(2020, 1, 1).and_hms(0, 0, 0),
            after: UTC.ymd(2020, 1, 1).and_hms(0, 0, 0),
            dt: UTC.ymd(2020, 1, 1).and_hms(0, 0, 0),
        };
        let mut iter_res = IterResult::new(QueryMethodTypes::ALL, iter_args);

        let res = iter_v2(&mut iter_res, &mut self.options);
        res
    }

    pub fn between(
        &mut self,
        after: &DateTime<Tz>,
        before: &DateTime<Tz>,
        inc: bool,
    ) -> Vec<DateTime<Tz>> {
        let iter_args = IterArgs {
            inc,
            before: before.clone(),
            after: after.clone(),
            dt: UTC.ymd(2020, 1, 1).and_hms(0, 0, 0),
        };
        let mut iter_res = IterResult::new(QueryMethodTypes::ALL, iter_args);

        let res = iter_v2(&mut iter_res, &mut self.options);
        res
    }
}