pub struct Timeline { /* private fields */ }Expand description
A sequence of ordered, non-overlapping intervals and associated values.
Intervals are sorted by their timestamp. The intervals will not overlap, but there may be gaps between intervals.
Implementations§
Source§impl Timeline
impl Timeline
Sourcepub fn from_events(
program: &Program,
events: Vec<&EventContent>,
) -> Option<Self>
pub fn from_events( program: &Program, events: Vec<&EventContent>, ) -> Option<Self>
Creates a Timeline form a Program, and the Events that belong to it.
It sorts events according to their priority and builds the timeline accordingly. The timeline can have gaps if the intervals in the events contain gaps. The event with the highest priority always takes presence at a specific time point. Therefore, a long-lasting, low-priority event can be interrupted by a short, high-priority event, for example. In this case, the long-lasting event will be split into two parts, such that the high-priority event fits in between.
Input:
|------------------------long, low prio--------------------------| |--another-interval--|
|-----short, high prio---|
Result:
|--long, low prio--|-----short, high prio---|---long, low prio---| |--another-interval--|This function logs at warn level if provided with an Event
those program_id does not match with the Program::id.
The corresponding event will be ignored then building the timeline.
This function also logs at warn
level if there are two overlapping events at the same priority.
There is no guarantee which event will take precedence, though in the current implementation
the event stored later in the events param will take precedence.
There must be an IntervalPeriod present on the event level,
or the individual intervals.
If both are specified, the individual period takes precedence over the one specified in the event.
If for an interval, there is no period present, and none specified in the event,
then this function will return None
Sourcepub fn at_datetime(
&self,
datetime: &DateTime<Utc>,
) -> Option<(&Range<DateTime<Utc>>, Interval<'_>)>
pub fn at_datetime( &self, datetime: &DateTime<Utc>, ) -> Option<(&Range<DateTime<Utc>>, Interval<'_>)>
Returns the Interval applicable at the requested time point and the range it is valid for.
Sourcepub fn next_update(&self, datetime: &DateTime<Utc>) -> Option<DateTime<Utc>>
pub fn next_update(&self, datetime: &DateTime<Utc>) -> Option<DateTime<Utc>>
Returns the time when to next change takes effect.
Example:
|--interval 1--|---interval 2---| |---interval 3---|
↑ ↑ ↑ ↑ ↑
08:03 09:56 10:59 11:01 12:00For the timeline illustrated above,
next_update(09:56)would returnSome(10:59)next_update(10:00)would returnSome(10:59)next_update(11:00)would returnSome(11:01)next_update(12:00)would returnNonenext_update(12:01)would returnNone