Evaluate REMINDs

This commit is contained in:
Joscha 2021-12-21 00:14:14 +01:00
parent fe22c66c5c
commit 66da16f4e3
6 changed files with 115 additions and 29 deletions

View file

@ -4,13 +4,14 @@ use crate::files::commands::BirthdaySpec;
use super::super::command::CommandState;
use super::super::date::Dates;
use super::super::error::Result;
use super::super::EntryKind;
impl<'a> CommandState<'a> {
pub fn eval_birthday_spec(&mut self, spec: &BirthdaySpec) {
let range = match self.limit_from_until(self.range) {
pub fn eval_birthday_spec(&mut self, spec: &BirthdaySpec) -> Result<()> {
let range = match self.limit_from_until(self.range_with_remind()) {
Some(range) => range,
None => return,
None => return Ok(()),
};
for year in range.years() {
@ -26,15 +27,19 @@ impl<'a> CommandState<'a> {
let kind = EntryKind::Birthday(age);
if let Some(date) = spec.date.with_year(year) {
self.add(EntryKind::Birthday(age), Some(Dates::new(date, date)));
self.add(
self.entry_with_remind(EntryKind::Birthday(age), Some(Dates::new(date, date)))?,
);
} else {
assert_eq!(spec.date.month(), 2);
assert_eq!(spec.date.day(), 29);
let first = NaiveDate::from_ymd(year, 2, 28);
let second = NaiveDate::from_ymd(year, 3, 1);
self.add(kind, Some(Dates::new(first, second)));
self.add(self.entry_with_remind(kind, Some(Dates::new(first, second)))?);
}
}
Ok(())
}
}

View file

@ -84,7 +84,7 @@ impl DateSpec {
.map(|date| date.succ())
.unwrap_or(self.start);
let range = s
.range
.range_with_remind()
.expand_by(&self.end_delta)
.move_by(&self.start_delta)
.with_from(range_from)?;
@ -93,7 +93,7 @@ impl DateSpec {
Command::Note(_) => {
let start = self.start;
let range = s
.range
.range_with_remind()
.expand_by(&self.end_delta)
.move_by(&self.start_delta);
(start, false, range)
@ -142,13 +142,13 @@ impl<'a> CommandState<'a> {
}
while start <= range.until() {
let dates = spec.dates(index, start)?;
self.add(self.kind(), Some(dates));
self.add(self.entry_with_remind(self.kind(), Some(dates))?);
start = DateSpec::step(index, start, repeat)?;
}
}
} else {
let dates = spec.dates(index, spec.start)?;
self.add(self.kind(), Some(dates));
self.add(self.entry_with_remind(self.kind(), Some(dates))?);
}
Ok(())
}

View file

@ -324,7 +324,7 @@ impl From<&commands::WeekdaySpec> for FormulaSpec {
impl FormulaSpec {
fn range(&self, s: &CommandState<'_>) -> Option<DateRange> {
let mut range = s
.range
.range_with_remind()
.expand_by(&self.end_delta)
.move_by(&self.start_delta);
@ -367,7 +367,7 @@ impl<'a> CommandState<'a> {
for day in range.days() {
if spec.eval(index, day)? {
let dates = spec.dates(index, day)?;
self.add(self.kind(), Some(dates));
self.add(self.entry_with_remind(self.kind(), Some(dates))?);
}
}
}