Skip to main content

perspective_viewer/config/
datetime_column_style.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
13mod custom;
14mod custom_format;
15mod simple;
16mod simple_format;
17
18pub use custom::*;
19pub use custom_format::*;
20use serde::{Deserialize, Serialize};
21pub use simple::*;
22pub use simple_format::*;
23use ts_rs::TS;
24
25/// `Simple` case has all default-able keys and must be last!
26#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
27// #[serde(tag = "format", content = "date_format")]
28#[serde(untagged)]
29pub enum DatetimeFormatType {
30    // #[serde(rename = "custom")]
31    Custom(CustomDatetimeStyleConfig),
32    Simple(SimpleDatetimeStyleConfig),
33}
34
35impl Default for DatetimeFormatType {
36    fn default() -> Self {
37        Self::Simple(SimpleDatetimeStyleConfig::default())
38    }
39}
40
41impl DatetimeFormatType {
42    pub fn time_zone(&self) -> &Option<String> {
43        match self {
44            DatetimeFormatType::Custom(x) => &x.time_zone,
45            DatetimeFormatType::Simple(x) => &x.time_zone,
46        }
47    }
48
49    pub fn time_zone_mut(&mut self) -> &mut Option<String> {
50        match self {
51            DatetimeFormatType::Custom(x) => &mut x.time_zone,
52            DatetimeFormatType::Simple(x) => &mut x.time_zone,
53        }
54    }
55}
56
57/// A model for the JSON serialized style configuration for a column of type
58/// `datetime`.
59#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize, TS)]
60// #[derive(WasmDescribe!, FromWasmAbi!)]
61pub struct DatetimeColumnStyleConfig {
62    #[serde(default)]
63    #[serde(skip_serializing_if = "Option::is_none")]
64    #[ts(optional, as = "Option<_>")]
65    pub date_format: Option<DatetimeFormatType>,
66}