Restructure eval module
This commit is contained in:
parent
817732abf6
commit
35184e21e9
5 changed files with 208 additions and 199 deletions
32
src/eval/range.rs
Normal file
32
src/eval/range.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue