use core::fmt;
use jiff::Timestamp;
use jiff::tz::Offset;
use crate::text::{Charset, TextSpec, Ws};
use crate::text_type;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Zeitstempel {
pub timestamp: Timestamp,
pub offset: Offset,
}
impl Zeitstempel {
#[must_use]
pub fn berlin(timestamp: Timestamp) -> Self {
Self { timestamp, offset: crate::calendar::berlin().to_offset(timestamp) }
}
#[must_use]
pub const fn utc(timestamp: Timestamp) -> Self {
Self { timestamp, offset: Offset::UTC }
}
}
impl From<Timestamp> for Zeitstempel {
fn from(timestamp: Timestamp) -> Self {
Self::berlin(timestamp)
}
}
impl fmt::Display for Zeitstempel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.timestamp.display_with_offset(self.offset))
}
}
text_type!(
SignaturText,
TextSpec { name: "SignaturText", min: 0, max: usize::MAX, charset: Charset::Wbci, ws: Ws::Replace, pattern: None },
plain
);
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SignaturId {
pub issuer: SignaturText,
pub serial: SignaturText,
}