use std::time::{SystemTime, SystemTimeError, UNIX_EPOCH};
use miette::Diagnostic;
use thiserror::Error;
pub const CURRENT_TIME_BEFORE_EPOCH: &str = "current time is before the epoch";
#[derive(Debug, Error, Diagnostic)]
#[error("system time is before epoch")]
#[diagnostic(code(otp_std::time), help("see the report for more information"))]
pub struct Error(#[from] pub SystemTimeError);
pub fn now() -> Result<u64, Error> {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|duration| duration.as_secs())
.map_err(Error)
}
pub fn expect_now() -> u64 {
now().expect(CURRENT_TIME_BEFORE_EPOCH)
}