perspective_viewer/config/datetime_column_style/
simple_format.rs1use std::fmt::Display;
14use std::str::FromStr;
15
16use serde::{Deserialize, Serialize};
17use strum::EnumIter;
18use ts_rs::TS;
19
20#[derive(Clone, Copy, Debug, Default, Deserialize, EnumIter, Eq, PartialEq, Serialize, TS)]
21pub enum SimpleDatetimeFormat {
22 #[serde(rename = "full")]
23 Full,
24
25 #[serde(rename = "long")]
26 Long,
27
28 #[serde(rename = "medium")]
29 Medium,
30
31 #[default]
32 #[serde(rename = "short")]
33 Short,
34
35 #[serde(rename = "disabled")]
36 Disabled,
37}
38
39impl SimpleDatetimeFormat {
40 pub fn is_short(&self) -> bool {
41 self == &Self::Short
42 }
43
44 pub fn is_medium(&self) -> bool {
45 self == &Self::Medium
46 }
47
48 pub const fn values() -> &'static [Self] {
49 &[
50 Self::Full,
51 Self::Long,
52 Self::Medium,
53 Self::Short,
54 Self::Disabled,
55 ]
56 }
57}
58
59impl Display for SimpleDatetimeFormat {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 let text = match self {
62 Self::Full => "full",
63 Self::Long => "long",
64 Self::Medium => "medium",
65 Self::Short => "short",
66 Self::Disabled => "disabled",
67 };
68
69 write!(f, "{text}")
70 }
71}
72
73impl FromStr for SimpleDatetimeFormat {
74 type Err = String;
75
76 fn from_str(s: &str) -> Result<Self, Self::Err> {
77 match s {
78 "full" => Ok(Self::Full),
79 "long" => Ok(Self::Long),
80 "medium" => Ok(Self::Medium),
81 "short" => Ok(Self::Short),
82 "disabled" => Ok(Self::Disabled),
83 x => Err(format!("Unknown DatetimeFormat::{x}")),
84 }
85 }
86}