scsys_core/time/
epoch.rs

1/*
2    Appellation: epoch <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5use super::Timestamp;
6
7#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
8#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
9pub struct Epoch<T = u128> {
10    size: u128,
11    timestamp: Timestamp<T>,
12}
13
14impl<T> Epoch<T> {
15    pub fn new(size: u128, timestamp: Timestamp<T>) -> Self {
16        Self { size, timestamp }
17    }
18    /// The size of the epoch; epochs generally consider the number of steps, or size,
19    /// (e.g. the number of seconds) that will need to be taken before the epoch is considered
20    /// to be complete and a new one begins.
21    pub fn size(&self) -> u128 {
22        self.size
23    }
24
25    pub fn timestamp(&self) -> &T {
26        &self.timestamp
27    }
28
29    pub fn set_size(&mut self, size: u128) {
30        self.size = size;
31    }
32}