Skip to main content

cesr/core/primitives/
dater.rs

1use alloc::borrow::Cow;
2
3/// ISO-8601 `DateTime` encoded as CESR Matter.
4/// Code is always `MatterCode::DateTime` (`1AAG`).
5pub struct Dater<'a> {
6    datetime: Cow<'a, str>,
7}
8
9impl<'a> Dater<'a> {
10    /// Creates a `Dater` from an ISO-8601 datetime string.
11    #[must_use]
12    pub const fn new(datetime: Cow<'a, str>) -> Self {
13        Self { datetime }
14    }
15
16    /// Returns the stored datetime string.
17    #[must_use]
18    pub fn datetime(&self) -> &str {
19        self.datetime.as_ref()
20    }
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26    use alloc::borrow::Cow;
27
28    #[test]
29    fn dater_holds_datetime_string() {
30        let dt = Dater::new(Cow::from("2025-03-01T00:00:00.000000+00:00"));
31        assert_eq!(dt.datetime(), "2025-03-01T00:00:00.000000+00:00");
32    }
33}