Debian Codegraph @

examples/roster.rs

raw symbols SCIP
1 use chrono::offset::TimeZone;
2 use chrono::{Duration, Utc};
3 use rangemap::RangeMap;
4
5 fn main() {
6 let people = ["Alice", "Bob", "Carol"];
7 let mut roster = RangeMap::new();
8
9 // Set up initial roster.
10 let start_of_roster = Utc.with_ymd_and_hms(2019, 1, 7, 0, 0, 0).unwrap();
11 let mut week_start = start_of_roster;
12 for _ in 0..3 {
13 for person in &people {
14 let next_week = week_start + Duration::weeks(1);
15 roster.insert(week_start..next_week, person);
16 week_start = next_week;
17 }
18 }
19
20 // Bob is covering Alice's second shift (the fourth shift overall).
21 let fourth_shift_start = start_of_roster + Duration::weeks(3);
22 let fourth_shift_end = fourth_shift_start + Duration::weeks(1);
23 roster.insert(fourth_shift_start..fourth_shift_end, &"Bob");
24
25 // Print out the roster, and observe that
26 // the fourth and fifth shifts have been coalesced
27 // into one range.
28 for (range, person) in roster.iter() {
29 println!("{} ({}): {}", range.start, range.end - range.start, person);
30 }
31 }