From 6277be699e613756fb786a524f71ddbe509ab81e Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 20 Mar 2022 12:56:16 +0100 Subject: Fix until being considered before end getting reps --- src/model/repetition.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/model') diff --git a/src/model/repetition.rs b/src/model/repetition.rs index eb8cb6d..155545f 100644 --- a/src/model/repetition.rs +++ b/src/model/repetition.rs @@ -49,7 +49,7 @@ impl Repetition { let repeat = |mut date, next: Box NaiveDate>| { let mut repetitions = vec![]; let mut iteration: usize = 0; - let end = self.until.unwrap_or(end); + let end = self.until.map(|u| u.min(end)).unwrap_or(end); while date <= end { if date >= event { if date >= start && !self.removed_occurences.contains(&iteration) { @@ -276,6 +276,19 @@ mod tests { ) } + #[test] + fn repetition_daily_after_day() { + let repetition = Repetition { + frequency: Frequency::Daily { period: 1 }, + removed_occurences: HashSet::new(), + until: Some(d(2022, 4, 17)), + }; + assert_eq!( + repetition.between(d(2022, 4, 4), d(2022, 3, 20), d(2022, 3, 20)), + vec!() + ) + } + fn d(y: i32, m: u32, d: u32) -> NaiveDate { NaiveDate::from_ymd(y, m, d) } -- cgit v1.2.3