Skip to main content

logicaffeine_system/
temporal.rs

1//! Temporal types for Logicaffeine. The date, moment, time-of-day and calendar span values are
2//! `logicaffeine-data`'s ([`logicaffeine_data::temporal`]), where every value model reaches them, re-exported
3//! here beside what only a system has: the clock, and how `Show` prints them.
4
5use std::fmt::{self, Display};
6
7pub use logicaffeine_data::temporal::*;
8
9/// The instant the system clock reads now.
10#[cfg(not(target_arch = "wasm32"))]
11pub fn current_moment() -> LogosMoment {
12    use std::time::{SystemTime, UNIX_EPOCH};
13    let duration = SystemTime::now()
14        .duration_since(UNIX_EPOCH)
15        .unwrap_or_default();
16    LogosMoment(duration.as_nanos() as i64)
17}
18
19impl crate::io::Showable for LogosDate {
20    fn format_show(&self, f: &mut fmt::Formatter) -> fmt::Result {
21        Display::fmt(self, f)
22    }
23}
24
25impl crate::io::Showable for LogosMoment {
26    fn format_show(&self, f: &mut fmt::Formatter) -> fmt::Result {
27        Display::fmt(self, f)
28    }
29}
30
31impl crate::io::Showable for LogosSpan {
32    fn format_show(&self, f: &mut fmt::Formatter) -> fmt::Result {
33        Display::fmt(self, f)
34    }
35}
36
37impl crate::io::Showable for LogosTime {
38    fn format_show(&self, f: &mut fmt::Formatter) -> fmt::Result {
39        Display::fmt(self, f)
40    }
41}