perspective_viewer/config/datetime_column_style/
simple.rs

1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ ██████ ██████ ██████       █      █      █      █      █ █▄  ▀███ █       ┃
3// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█  ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄  ▀█ █ ▀▀▀▀▀ ┃
4// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄   █ ▄▄▄▄▄ ┃
5// ┃ █      ██████ █  ▀█▄       █ ██████      █      ███▌▐███ ███████▄ █       ┃
6// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7// ┃ Copyright (c) 2017, the Perspective Authors.                              ┃
8// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9// ┃ This file is part of the Perspective library, distributed under the terms ┃
10// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
13use serde::{Deserialize, Serialize};
14use ts_rs::TS;
15
16use super::simple_format::*;
17
18const fn date_style_default() -> SimpleDatetimeFormat {
19    SimpleDatetimeFormat::Short
20}
21
22const fn time_style_default() -> SimpleDatetimeFormat {
23    SimpleDatetimeFormat::Medium
24}
25
26#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
27pub struct SimpleDatetimeStyleConfig {
28    #[serde(default)]
29    #[serde(rename = "timeZone", skip_serializing_if = "Option::is_none")]
30    pub time_zone: Option<String>,
31
32    #[serde(
33        default = "date_style_default",
34        rename = "dateStyle",
35        skip_serializing_if = "SimpleDatetimeFormat::is_short"
36    )]
37    pub date_style: SimpleDatetimeFormat,
38
39    #[serde(
40        default = "time_style_default",
41        rename = "timeStyle",
42        skip_serializing_if = "SimpleDatetimeFormat::is_medium"
43    )]
44    pub time_style: SimpleDatetimeFormat,
45}
46
47impl Default for SimpleDatetimeStyleConfig {
48    fn default() -> Self {
49        Self {
50            time_zone: None,
51            date_style: SimpleDatetimeFormat::Short,
52            time_style: SimpleDatetimeFormat::Medium,
53        }
54    }
55}