Skip to content

Commit

Permalink
refactor: Switch to !TimeOfDay tag
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Jan 7, 2023
1 parent ae04b63 commit bbff9dd
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"yaml.customTags": [
"!DayOfWeek sequence",
"!TimeOfDay mapping",
"!Unavailable mapping",
"!None",
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ will cover on-call (if you have part time employees, or people whose situations
shiftLength: 1 # A new shift starts every day
constraints:
- !DayOfWeek [Mon, Tue, Wed, Thu, Fri] # Shifts cover weekdays only
- !TimeRange # And run from 08:00 to 16:00 on those days
- !TimeOfDay # And run from 08:00 to 16:00 on those days
start: 08:00:00
end: 16:00:00
humans:
Expand Down
2 changes: 1 addition & 1 deletion examples/3-day.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
shiftLength: 3
constraints:
- !DayOfWeek [Mon, Tue, Wed, Thu, Fri]
- !TimeRange
- !TimeOfDay
start: 08:00:00
end: 16:00:00
humans:
Expand Down
2 changes: 1 addition & 1 deletion examples/rotation.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
shiftLength: 1
constraints:
- !DayOfWeek [Mon, Tue, Wed, Thu, Fri]
- !TimeRange
- !TimeOfDay
start: 08:00:00
end: 16:00:00
humans:
Expand Down
2 changes: 1 addition & 1 deletion examples/weekly.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
shiftLength: 5
constraints:
- !DayOfWeek [Mon, Tue, Wed, Thu, Fri]
- !TimeRange
- !TimeOfDay
start: 08:00:00
end: 16:00:00
humans:
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ mod tests {
shiftLength: 1
constraints:
- !DayOfWeek [Mon, Tue, Wed, Thu, Fri]
- !TimeRange
- !TimeOfDay
start: 08:00:00
end: 16:00:00
humans:
Expand Down
8 changes: 4 additions & 4 deletions src/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod unavailable;
pub enum Constraint {
None,
DayOfWeek(Vec<Weekday>),
TimeRange { start: NaiveTime, end: NaiveTime },
TimeOfDay { start: NaiveTime, end: NaiveTime },
Unavailable { start: NaiveDate, end: NaiveDate },
}

Expand All @@ -28,7 +28,7 @@ impl Constraint {
Constraint::DayOfWeek(days) => {
Box::new(dayofweek::DayOfWeekIterator::new(ranges, days.clone()))
}
Constraint::TimeRange { start, end } => {
Constraint::TimeOfDay { start, end } => {
Box::new(timeofday::TimeOfDayIterator::new(ranges, *start, *end))
}
Constraint::Unavailable { start, end } => {
Expand All @@ -45,7 +45,7 @@ impl Display for Constraint {
Constraint::DayOfWeek(days) => {
write!(f, "available on {:?}", days)
}
Constraint::TimeRange { start, end } => {
Constraint::TimeOfDay { start, end } => {
write!(f, "available between {} and {}", start, end)
}
Constraint::Unavailable { start, end } => {
Expand All @@ -61,7 +61,7 @@ mod tests {

#[test]
fn test_time_of_day_constraint() {
let constraint = Constraint::TimeRange {
let constraint = Constraint::TimeOfDay {
start: NaiveTime::from_hms_opt(9, 0, 0).unwrap(),
end: NaiveTime::from_hms_opt(17, 0, 0).unwrap(),
};
Expand Down
2 changes: 1 addition & 1 deletion src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ mod tests {
chrono::Weekday::Thu,
chrono::Weekday::Fri,
]),
Constraint::TimeRange {
Constraint::TimeOfDay {
start: NaiveTime::from_hms_opt(9, 0, 0).unwrap(),
end: NaiveTime::from_hms_opt(17, 0, 0).unwrap(),
},
Expand Down

0 comments on commit bbff9dd

Please sign in to comment.