zugferd_code_lists/zugferd_2_3_3/
date.rs1#![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,
11 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 = crate::ParseError<Self>;
25 fn from_str(s: &str) -> Result<Self, Self::Err> {
26 <Self as crate::FromCode>::from_code(s)
27 .ok_or_else(|| crate::ParseError::<Self>::new(s.to_owned()))
28 }
29}
30
31impl crate::Code for Date {
32 fn code(self) -> &'static str {
33 match self {
34 Date::Ccyymmdd => "102",
35 Date::Ccyymmddhhmmzhhmm => "205",
36 }
37 }
38}
39
40impl crate::Description for Date {
41 fn description(self) -> &'static str {
42 match self {
43 Date::Ccyymmdd => "CCYYMMDD",
44 Date::Ccyymmddhhmmzhhmm => "CCYYMMDDHHMMZHHMM",
45 }
46 }
47}
48
49impl crate::FromCode for Date {
50 fn from_code(code: &str) -> Option<Self>
51 where
52 Self: Sized,
53 {
54 match code {
55 "102" => Some(Date::Ccyymmdd),
56 "205" => Some(Date::Ccyymmddhhmmzhhmm),
57 _ => None,
58 }
59 }
60}