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/// A datetime column's `date_format` in its `Simple` preset form:
27/// `Intl.DateTimeFormatOptions`' `dateStyle`/`timeStyle` presets. This is
28/// the default form (no `format` key); setting `format: "custom"` selects
29/// the per-part `CustomDatetimeStyleConfig` instead.
30#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
31pub struct SimpleDatetimeStyleConfig {
32 /// An IANA time zone name (e.g. `"America/New_York"`); defaults to the
33 /// browser's local time zone.
34 #[serde(default)]
35 #[serde(rename = "timeZone", skip_serializing_if = "Option::is_none")]
36 pub time_zone: Option<String>,
37
38 /// Date preset breadth, or `"disabled"` to omit the date entirely;
39 /// defaults to `"short"`.
40 #[serde(
41 default = "date_style_default",
42 rename = "dateStyle",
43 skip_serializing_if = "SimpleDatetimeFormat::is_short"
44 )]
45 pub date_style: SimpleDatetimeFormat,
46
47 /// Time preset breadth, or `"disabled"` to omit the time entirely;
48 /// defaults to `"medium"`.
49 #[serde(
50 default = "time_style_default",
51 rename = "timeStyle",
52 skip_serializing_if = "SimpleDatetimeFormat::is_medium"
53 )]
54 pub time_style: SimpleDatetimeFormat,
55}
56
57impl Default for SimpleDatetimeStyleConfig {
58 fn default() -> Self {
59 Self {
60 time_zone: None,
61 date_style: SimpleDatetimeFormat::Short,
62 time_style: SimpleDatetimeFormat::Medium,
63 }
64 }
65}