smgw/management/
window.rs1use super::{Record, invalid};
2use std::io;
3
4#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
6pub struct ProfileWindow(i64);
7
8impl ProfileWindow {
9 pub fn new(first: i64) -> io::Result<Self> {
11 const FIRST: i64 = -62_167_219_200;
14 const LAST: i64 = 2_005_917_606_900;
15 if first % 900 != 0 || !(FIRST..=LAST).contains(&first) {
16 return Err(invalid("expected three representable quarter-hour slots"));
17 }
18 Ok(Self(first))
19 }
20
21 pub fn first(self) -> i64 {
23 self.0
24 }
25
26 pub fn validate(self, records: &[Record]) -> io::Result<()> {
28 if records.len() > 3
29 || records.iter().any(|r| {
30 !(self.0..=self.0 + 1800).contains(&r.reference_utc) || r.reference_utc % 900 != 0
31 })
32 || records
33 .windows(2)
34 .any(|pair| pair[0].reference_utc >= pair[1].reference_utc)
35 || records.iter().enumerate().any(|(i, r)| {
36 records[..i]
37 .iter()
38 .any(|p| p.measured_utc == r.measured_utc)
39 })
40 {
41 return Err(invalid("invalid or duplicate fixture profile slot"));
42 }
43 Ok(())
44 }
45}