summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/datetime.rs1
-rw-r--r--src/iter.rs2
-rw-r--r--src/options.rs9
-rw-r--r--tests/rrule.rs23
4 files changed, 27 insertions, 8 deletions
diff --git a/src/datetime.rs b/src/datetime.rs
index 3b78830..4c49edb 100644
--- a/src/datetime.rs
+++ b/src/datetime.rs
@@ -1,3 +1,4 @@
+#[derive(Debug)]
pub struct Time {
pub hour: usize,
pub minute: usize,
diff --git a/src/iter.rs b/src/iter.rs
index fe10479..401207e 100644
--- a/src/iter.rs
+++ b/src/iter.rs
@@ -108,6 +108,7 @@ pub fn iter(iter_result: &mut IterResult, options: &mut ParsedOptions) -> Vec<Da
};
loop {
+ println!("Main loop");
let (dayset, start, end) = ii.getdayset(
&options.freq,
counter_date.year() as isize,
@@ -146,6 +147,7 @@ pub fn iter(iter_result: &mut IterResult, options: &mut ParsedOptions) -> Vec<Da
}
}
} else {
+ println!("start: {}, end: {}", start, end);
for j in start..end {
let current_day = dayset[j];
if current_day.is_none() {
diff --git a/src/options.rs b/src/options.rs
index 257eb17..729a8d4 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -1,3 +1,4 @@
+use crate::yearinfo::*;
use chrono::prelude::*;
#[derive(Debug)]
@@ -47,18 +48,18 @@ pub struct ParsedOptions {
pub bynweekday: Vec<Vec<isize>>,
}
impl ParsedOptions {
- pub fn new(freq: Frequenzy, interval: usize, dtstart: &DateTime<Utc>) -> Self {
+ pub fn new(freq: Frequenzy, dtstart: &DateTime<Utc>) -> Self {
Self {
freq,
- interval,
+ interval: 1,
count: None,
until: None,
tzid: None,
dtstart: dtstart.clone(),
wkst: 0,
bysetpos: vec![],
- bymonth: vec![],
- bymonthday: vec![],
+ bymonth: vec![dtstart.month() as usize],
+ bymonthday: vec![dtstart.day() as usize],
bynmonthday: vec![],
byyearday: vec![],
byweekno: vec![],
diff --git a/tests/rrule.rs b/tests/rrule.rs
index 4f96320..6330073 100644
--- a/tests/rrule.rs
+++ b/tests/rrule.rs
@@ -21,7 +21,7 @@ mod test {
Utc.ymd(year, month, day).and_hms(hour, minute, second)
}
- fn test_recurring(msg: &str, options: &mut ParsedOptions, expected_dates: &Vec<DateTime<Utc>>) {
+ fn test_recurring(options: &mut ParsedOptions, expected_dates: &Vec<DateTime<Utc>>) {
let iter_args = IterArgs {
inc: true,
before: Utc::now(),
@@ -38,19 +38,20 @@ mod test {
"Expected number of returned dates to be equal to the expected"
);
+ println!("Acutal: {:?}", res);
for (actual, exptected) in res.iter().zip(expected_dates) {
- assert_eq!(actual, exptected, "{}", msg);
+ assert_eq!(actual, exptected);
}
}
#[test]
fn int_works() {
- let mut options = ParsedOptions::new(Frequenzy::WEEKLY, 5, &ymd_hms(2012, 1, 1, 10, 30, 0))
+ let mut options = ParsedOptions::new(Frequenzy::WEEKLY, &ymd_hms(2012, 1, 1, 10, 30, 0))
+ .interval(5)
.count(3)
.byweekday(vec![0, 4])
.bymonth(vec![6]);
test_recurring(
- "should work",
&mut options,
&vec![
ymd_hms(2012, 6, 18, 10, 30, 0),
@@ -59,4 +60,18 @@ mod test {
],
);
}
+
+ #[test]
+ fn yearly() {
+ let mut options =
+ ParsedOptions::new(Frequenzy::YEARLY, &ymd_hms(1997, 9, 2, 9, 0, 0)).count(3);
+ test_recurring(
+ &mut options,
+ &vec![
+ ymd_hms(1997, 9, 2, 9, 0, 0),
+ ymd_hms(1998, 9, 2, 9, 0, 0),
+ ymd_hms(1999, 9, 2, 9, 0, 0),
+ ],
+ );
+ }
}