Skip to content

Commit

Permalink
Handle concurrent events happening next in now/next
Browse files Browse the repository at this point in the history
  • Loading branch information
DanNixon committed May 4, 2024
1 parent 4037946 commit 4dee184
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion client/src/schedule/now_and_next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,24 @@ impl NowAndNext {
})
.collect();

// Find the next event to happen in the future.
// This will determine the start time of the next event(s).
let events_next = match events
.iter()
.find(|e| e.venue == venue && e.relative_to(now) == RelativeTime::Future)
{
Some(e) => vec![e.clone()],
// Then find all events that have the same start time.
// This set of events are the next to happen at the venue in question.
Some(first_future_event) => events
.iter()
.filter_map(|e| {
if e.venue == venue && e.start == first_future_event.start {
Some(e.clone())
} else {
None
}
})
.collect(),
None => Vec::default(),
};

Expand Down Expand Up @@ -190,4 +203,51 @@ mod test {
);
assert_eq!(now_and_next.guide["venue 1"].next, vec![events[3].clone()]);
}

#[test]
fn concurrent_next() {
let events = vec![
{
let mut e = Event::dummy(
DateTime::parse_from_rfc3339("2024-03-12T20:00:00+00:00").unwrap(),
);
e.venue = "venue 1".to_owned();
e
},
{
let mut e = Event::dummy(
DateTime::parse_from_rfc3339("2024-03-12T20:00:00+00:00").unwrap(),
);
e.venue = "venue 2".to_owned();
e
},
{
let mut e = Event::dummy(
DateTime::parse_from_rfc3339("2024-03-12T20:00:00+00:00").unwrap(),
);
e.venue = "venue 1".to_owned();
e
},
{
let mut e = Event::dummy(
DateTime::parse_from_rfc3339("2024-03-12T21:00:00+00:00").unwrap(),
);
e.venue = "venue 1".to_owned();
e
},
];

let t = DateTime::parse_from_rfc3339("2024-03-12T19:59:59+00:00").unwrap();
let now_and_next = NowAndNext::new(&events, t);

assert_eq!(now_and_next.now, t);

assert_eq!(now_and_next.guide.len(), 2);

assert_eq!(now_and_next.guide["venue 1"].now, Vec::default(),);
assert_eq!(
now_and_next.guide["venue 1"].next,
vec![events[0].clone(), events[2].clone()]
);
}
}

0 comments on commit 4dee184

Please sign in to comment.