Fix when and how reminders are calculated and displayed

This commit is contained in:
Joscha 2021-12-21 19:46:36 +01:00
parent 73a44a697a
commit 07ce85982c

View file

@ -81,7 +81,11 @@ impl DayLayout {
fn layout_task(&mut self, index: usize, entry: &Entry) { fn layout_task(&mut self, index: usize, entry: &Entry) {
if let Some(dates) = entry.dates { if let Some(dates) = entry.dates {
let (start, end) = dates.sorted().dates(); let (start, end) = dates.sorted().dates();
if self.today < start { if self.today < self.range.from() || self.range.until() < self.today {
// If `self.today` is not in range, reminders won't be displayed
// (since they're always displayed on `self.today`) so there's
// no need to calculate them.
} else if self.today < start {
if let Some(remind) = entry.remind { if let Some(remind) = entry.remind {
if remind <= self.today { if remind <= self.today {
let days = (start - self.today).num_days(); let days = (start - self.today).num_days();
@ -118,7 +122,18 @@ impl DayLayout {
fn layout_note(&mut self, index: usize, entry: &Entry) { fn layout_note(&mut self, index: usize, entry: &Entry) {
if let Some(dates) = entry.dates { if let Some(dates) = entry.dates {
let (start, end) = dates.sorted().dates(); let (start, end) = dates.sorted().dates();
if start < self.range.from() && self.range.until() < end { if self.today < self.range.from() || self.range.until() < self.today {
// if `self.today` is not in range, reminders won't be displayed
// (since they're always displayed on `self.today`) so there's
// no need to calculate them.
} else if self.today < start {
if let Some(remind) = entry.remind {
if remind <= self.today {
let days = (start - self.today).num_days();
self.insert(self.today, DayEntry::ReminderUntil(index, days));
}
}
} else if start < self.range.from() && self.range.until() < end {
// This note applies to the current day, but it won't appear if // This note applies to the current day, but it won't appear if
// we just layout it as a dated entry, so instead we add it as a // we just layout it as a dated entry, so instead we add it as a
// reminder. Since we are usually more interested in when // reminder. Since we are usually more interested in when
@ -126,9 +141,8 @@ impl DayLayout {
// the end. // the end.
let days = (end - self.today).num_days(); let days = (end - self.today).num_days();
self.insert(self.today, DayEntry::ReminderWhile(index, days)); self.insert(self.today, DayEntry::ReminderWhile(index, days));
} else {
self.layout_dated_entry(index, dates);
} }
self.layout_dated_entry(index, dates);
} else { } else {
self.insert(self.today, DayEntry::Undated(index)); self.insert(self.today, DayEntry::Undated(index));
} }