cartulary 0.3.0-alpha.1

The knowledge layer of your project — decisions, issues, docs, all in one place.
Documentation
//! System-clock adapter for the [`Clock`] port.
//!
//! Reads `chrono::Utc::now()` / `chrono::Local::now()`; the only place
//! in the codebase where wall-clock time is sourced.

use chrono::{Local, Utc};

use crate::domain::model::temporal::iso_date::IsoDate;
use crate::domain::model::temporal::timestamp::Timestamp;
use crate::domain::usecases::clock::Clock;

pub struct SystemClock;

impl Clock for SystemClock {
    fn now(&self) -> Timestamp {
        Timestamp::new(&Utc::now().format("%Y-%m-%dT%H:%M:%SZ").to_string())
            .expect("UTC::now formatted with %Y-%m-%dT%H:%M:%SZ is always a valid Timestamp")
    }

    fn today_local(&self) -> IsoDate {
        IsoDate::new(&Local::now().format("%Y-%m-%d").to_string())
            .expect("Local::now formatted with %Y-%m-%d is always a valid IsoDate")
    }
}