openleadr_wire/
interval.rs

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