aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2022-03-20 12:56:16 +0100
committerJoris2022-03-20 12:56:16 +0100
commit6277be699e613756fb786a524f71ddbe509ab81e (patch)
treefa78cb941f2d66c212825d67758766cbf45d1310
parentfc5d0bcd25059e45064478710aa2943d8369dcd0 (diff)
Fix until being considered before end getting reps
-rw-r--r--README.md8
-rw-r--r--src/model/repetition.rs15
2 files changed, 18 insertions, 5 deletions
diff --git a/README.md b/README.md
index de17573..a033b4e 100644
--- a/README.md
+++ b/README.md
@@ -18,11 +18,11 @@ cargo test
## Description
-- Add description textarea field
+- Add description textarea field.
## Optimizations
-- Optimize refresh
+- Optimize refresh.
## Categorize events
@@ -31,12 +31,12 @@ cargo test
## Multi day events
-- Try width parameter using grid.attach
+- Try width parameter using grid.attach.
## Nice to have
- Drag & drop events.
-- Prevent to launch multiple instances.
+- Prevent launching multiple instances.
- Show a date picker in dialog form.
- Print errors on forms when validating.
- Validate the form when pressing enter on any field.
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<dyn Fn(NaiveDate) -> 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)
}