1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
use std::fmt::Display;
use std::str::FromStr;
use serde::{Deserialize, Serialize};
use strum::EnumIter;
use ts_rs::TS;
#[derive(Clone, Copy, Debug, Default, Deserialize, EnumIter, Eq, PartialEq, Serialize, TS)]
pub enum SimpleDatetimeFormat {
#[serde(rename = "full")]
Full,
#[serde(rename = "long")]
Long,
#[serde(rename = "medium")]
Medium,
#[default]
#[serde(rename = "short")]
Short,
#[serde(rename = "disabled")]
Disabled,
}
impl SimpleDatetimeFormat {
pub fn is_short(&self) -> bool {
self == &Self::Short
}
pub fn is_medium(&self) -> bool {
self == &Self::Medium
}
pub const fn values() -> &'static [Self] {
&[
Self::Full,
Self::Long,
Self::Medium,
Self::Short,
Self::Disabled,
]
}
}
impl Display for SimpleDatetimeFormat {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let text = match self {
Self::Full => "full",
Self::Long => "long",
Self::Medium => "medium",
Self::Short => "short",
Self::Disabled => "disabled",
};
write!(f, "{}", text)
}
}
impl FromStr for SimpleDatetimeFormat {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"full" => Ok(Self::Full),
"long" => Ok(Self::Long),
"medium" => Ok(Self::Medium),
"short" => Ok(Self::Short),
"disabled" => Ok(Self::Disabled),
x => Err(format!("Unknown DatetimeFormat::{}", x)),
}
}
}