umya_spreadsheet/structs/
time_period_values.rs1use std::str::FromStr;
2
3use super::EnumTrait;
4#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
5pub enum TimePeriodValues {
6 Last7Days,
7 LastMonth,
8 LastWeek,
9 NextMonth,
10 NextWeek,
11 ThisMonth,
12 ThisWeek,
13 Today,
14 Tomorrow,
15 Yesterday,
16}
17impl Default for TimePeriodValues {
18 #[inline]
19 fn default() -> Self {
20 Self::Today
21 }
22}
23impl EnumTrait for TimePeriodValues {
24 #[inline]
25 fn value_string(&self) -> &str {
26 match &self {
27 Self::Last7Days => "last7Days",
28 Self::LastMonth => "lastMonth",
29 Self::LastWeek => "lastWeek",
30 Self::NextMonth => "nextMonth",
31 Self::NextWeek => "nextWeek",
32 Self::ThisMonth => "thisMonth",
33 Self::ThisWeek => "thisWeek",
34 Self::Today => "today",
35 Self::Tomorrow => "tomorrow",
36 Self::Yesterday => "yesterday",
37 }
38 }
39}
40impl FromStr for TimePeriodValues {
41 type Err = ();
42
43 #[inline]
44 fn from_str(input: &str) -> Result<Self, Self::Err> {
45 match input {
46 "last7Days" => Ok(Self::Last7Days),
47 "lastMonth" => Ok(Self::LastMonth),
48 "lastWeek" => Ok(Self::LastWeek),
49 "nextMonth" => Ok(Self::NextMonth),
50 "nextWeek" => Ok(Self::NextWeek),
51 "thisMonth" => Ok(Self::ThisMonth),
52 "thisWeek" => Ok(Self::ThisWeek),
53 "today" => Ok(Self::Today),
54 "tomorrow" => Ok(Self::Tomorrow),
55 "yesterday" => Ok(Self::Yesterday),
56 _ => Err(()),
57 }
58 }
59}