Restructure eval module

This commit is contained in:
Joscha 2021-11-24 01:13:45 +01:00
parent 817732abf6
commit 35184e21e9
5 changed files with 208 additions and 199 deletions

32
src/eval/range.rs Normal file
View file

@ -0,0 +1,32 @@
use std::ops::RangeInclusive;
use chrono::{Datelike, NaiveDate};
#[derive(Debug, Clone, Copy)]
pub struct DateRange {
from: NaiveDate,
until: NaiveDate,
}
impl DateRange {
pub fn new(from: NaiveDate, until: NaiveDate) -> Self {
assert!(from <= until);
Self { from, until }
}
pub fn contains(&self, date: NaiveDate) -> bool {
self.from <= date && date <= self.until
}
pub fn from(&self) -> NaiveDate {
self.from
}
pub fn until(&self) -> NaiveDate {
self.until
}
pub fn years(&self) -> RangeInclusive<i32> {
self.from.year()..=self.until.year()
}
}