zugferd_code_lists/zugferd_2_3_2/
date.rs

1#![allow(non_camel_case_types)]
2
3#[cfg_attr(feature = "specta", derive(specta::Type))]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
6pub enum Date {
7    /// CCYYMMDD
8    ///
9    /// Calendar date: C = Century ; Y = Year ; M = Month ; D = Day.
10    Ccyymmdd,
11    /// CCYYMMDDHHMMZHHMM
12    ///
13    /// Calendar date including time and time zone expressed in hours and minutes. ZHHMM = time zone given as offset from Coordinated Universal Time (UTC).
14    Ccyymmddhhmmzhhmm,
15}
16
17impl std::fmt::Display for Date {
18    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19        write!(f, "{}", <Self as crate::Code>::code(*self))
20    }
21}
22
23impl std::str::FromStr for Date {
24    type Err = ();
25    fn from_str(s: &str) -> Result<Self, Self::Err> {
26        <Self as crate::FromCode>::from_code(s).ok_or(())
27    }
28}
29
30impl crate::Code for Date {
31    fn code(self) -> &'static str {
32        match self {
33            Date::Ccyymmdd => "102",
34            Date::Ccyymmddhhmmzhhmm => "205",
35        }
36    }
37}
38
39impl crate::Description for Date {
40    fn description(self) -> &'static str {
41        match self {
42            Date::Ccyymmdd => "CCYYMMDD",
43            Date::Ccyymmddhhmmzhhmm => "CCYYMMDDHHMMZHHMM",
44        }
45    }
46}
47
48impl crate::FromCode for Date {
49    fn from_code(code: &str) -> Option<Self>
50    where
51        Self: Sized,
52    {
53        match code {
54            "102" => Some(Date::Ccyymmdd),
55            "205" => Some(Date::Ccyymmddhhmmzhhmm),
56            _ => None,
57        }
58    }
59}