// This file is part of Moonfire NVR, a security camera network video recorder. // Copyright (C) 2021 The Moonfire NVR Authors; see AUTHORS and LICENSE.txt. // SPDX-License-Identifier: GPL-v3.0-or-later WITH GPL-3.0-linking-exception. //! In-memory indexes by calendar day. use base::time::{Duration, Time, TIME_UNITS_PER_SEC}; use base::{err, Error}; use smallvec::SmallVec; use std::cmp; use std::collections::BTreeMap; use std::convert::TryFrom; use std::io::Write; use std::ops::Range; use std::str; use tracing::{error, trace}; /// A calendar day in `YYYY-mm-dd` format. #[derive(Copy, Clone, Eq, Ord, PartialEq, PartialOrd)] pub struct Key(pub(crate) [u8; 10]); impl Key { fn new(tm: time::Tm) -> Result { let mut s = Key([0u8; 10]); write!( &mut s.0[..], "{}", tm.strftime("%Y-%m-%d") .map_err(|e| err!(Internal, source(e)))? )?; Ok(s) } pub fn bounds(&self) -> Range