checkpoint

This commit is contained in:
Ian Roddis
2021-12-08 10:54:01 -04:00
parent fde7a01e99
commit cadb5782f0

View File

@@ -64,11 +64,17 @@ pub enum DateSpec {
impl DateSpec { impl DateSpec {
/// Get exact date of event and its policy, if it occured in that year /// Get exact date of event and its policy, if it occured in that year
fn resolve(&self, year: i32) -> Option<(NaiveDate, AdjustmentPolicy)> { fn resolve(&self, start: NaiveDate, end: NaiveDate) -> Option<(Vec<NaiveDate>, AdjustmentPolicy)> {
use DateSpec::*; use DateSpec::*;
match self { match self {
SpecificDate { date, .. } => Some((*date, AdjustmentPolicy::NoAdjustment)), SpecificDate { date, .. } => {
if date < start || end < date {
None
} else {
Some((vec![*date], AdjustmentPolicy::NoAdjustment)),
}
}
DayOfMonth { DayOfMonth {
month, month,
day, day,
@@ -77,9 +83,14 @@ impl DateSpec {
observed, observed,
.. ..
} => { } => {
if valid_since.is_some() && valid_since.unwrap().year() > year { if valid_since > end || valid_until < start {
None None
} else if valid_until.is_some() && valid_until.unwrap().year() < year { } else {
start =
if valid_since.is_some() && valid_since.unwrap().year() > start {
None
} else if valid_until.is_some() && valid_until.unwrap().year() < end {
None None
} else { } else {
let date = NaiveDate::from_ymd(year, month.number_from_month(), *day); let date = NaiveDate::from_ymd(year, month.number_from_month(), *day);