openleadr_wire/interval.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
//! Descriptions of temporal periods
use crate::{values_map::ValuesMap, Duration};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
/// An object defining a temporal window and a list of valuesMaps. if intervalPeriod present may set
/// temporal aspects of interval or override event.intervalPeriod.
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Interval {
/// A client generated number assigned an interval object. Not a sequence number.
pub id: i32,
/// Defines default start and durations of intervals.
#[serde(skip_serializing_if = "Option::is_none")]
pub interval_period: Option<IntervalPeriod>,
/// A list of valuesMap objects.
pub payloads: Vec<ValuesMap>,
}
impl Interval {
pub fn new(id: i32, payloads: Vec<ValuesMap>) -> Self {
Self {
id,
interval_period: None,
payloads,
}
}
}
/// Defines temporal aspects of intervals. A duration of default null indicates infinity. A
/// randomizeStart of default null indicates no randomization.
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IntervalPeriod {
/// The start time of an interval or set of intervals.
#[serde(with = "crate::serde_rfc3339")]
pub start: DateTime<Utc>,
/// The duration of an interval or set of intervals.
pub duration: Option<Duration>,
/// Indicates a randomization time that may be applied to start.
pub randomize_start: Option<Duration>,
}
impl IntervalPeriod {
pub fn new(start: DateTime<Utc>) -> Self {
Self {
start,
duration: None,
randomize_start: None,
}
}
}