Fixing issue with date range

This commit is contained in:
Ian Roddis
2021-12-03 15:18:43 -04:00
parent ec8d5bee04
commit e5ea51ee26
3 changed files with 32 additions and 16 deletions

24
Cargo.lock generated
View File

@@ -478,6 +478,18 @@ dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "cronkin"
version = "0.1.0"
dependencies = [
"actix-web",
"chrono",
"crossbeam",
"pam",
"serde",
"serde_json",
]
[[package]]
name = "crossbeam"
version = "0.8.1"
@@ -601,18 +613,6 @@ dependencies = [
"syn",
]
[[package]]
name = "ezsched"
version = "0.1.0"
dependencies = [
"actix-web",
"chrono",
"crossbeam",
"pam",
"serde",
"serde_json",
]
[[package]]
name = "flate2"
version = "1.0.22"

View File

@@ -1,5 +1,5 @@
[package]
name = "ezsched"
name = "cronkin"
version = "0.1.0"
edition = "2021"

View File

@@ -155,6 +155,8 @@ impl Calendar {
) -> Option<NaiveDate> {
let mut actual = date.clone();
println!("Adjusting {:?}", date);
let is_blocked =
|x: NaiveDate| -> bool { (!self.dow.contains(&x.weekday())) || holidays.contains(&x) };
@@ -215,11 +217,12 @@ impl Calendar {
/// Returns the set of valid calendar dates within the specified range
pub fn date_range(&self, from: NaiveDate, to: NaiveDate) -> Vec<NaiveDate> {
let mut result = Vec::new();
let mut cur = from;
let mut cur = from.pred();
let year = from.year();
let mut holidays = self.get_holidays(cur);
while cur < to {
while cur <= to {
cur = cur.succ();
if cur.year() != year {
holidays = self.get_holidays(cur);
}
@@ -227,7 +230,6 @@ impl Calendar {
continue;
}
result.push(cur);
cur = cur.succ();
}
result
}
@@ -302,8 +304,22 @@ mod tests {
since: None,
until: None,
},
DateSpec::MonthDay {
month: January,
day: 1u32,
observed: AdjustmentPolicy::Next,
description: "New Years Day".to_owned(),
since: None,
until: None,
},
],
inherits: vec![],
};
let myrange = cal.date_range(
NaiveDate::from_ymd(2021, 12, 15),
NaiveDate::from_ymd(2022, 01, 15),
);
assert_eq!(myrange.len(), 20);
}
}