Skip to main content

rustolio_utils/time/
timezone.rs

1//
2// SPDX-License-Identifier: MPL-2.0
3//
4// Copyright (c) 2026 Tobias Binnewies. All rights reserved.
5//
6// This Source Code Form is subject to the terms of the Mozilla Public
7// License, v. 2.0. If a copy of the MPL was not distributed with this
8// file, You can obtain one at http://mozilla.org/MPL/2.0/.
9//
10
11use super::{MILLISECONDS_PER_HOUR, MILLISECONDS_PER_MINUTE};
12
13macro_rules! create_timezone {
14    (
15        $(
16            $(#[$attrs:meta])*
17            $abbr:ident, $short:literal, $long:literal, $positive:literal, $utch:literal, $utcm:literal
18        ),*
19    ) => {
20        #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
21        #[allow(non_camel_case_types)]
22        pub enum Timezone {
23            $(
24                $(#[$attrs])*
25                $abbr
26            ),*
27        }
28
29        impl Timezone {
30            pub const fn format_long(&self) -> &'static str {
31                match self {
32                    $(Timezone::$abbr => $long),*
33                }
34            }
35
36            pub const fn format_short(&self) -> &'static str {
37                match self {
38                    $(Timezone::$abbr => $short),*
39                }
40            }
41
42            pub const fn utc_offset_hours_min(&self) -> (bool, u8, u8) {
43                match self {
44                    $(Timezone::$abbr => ($positive, $utch, $utcm)),*
45                }
46            }
47
48            pub const fn utc_offset_millis(&self) -> i64 {
49                match self {
50                    $(Timezone::$abbr => {
51                        (if $positive { 1 } else { -1 } * MILLISECONDS_PER_HOUR * $utch + MILLISECONDS_PER_MINUTE * $utcm)
52                    }),*
53                }
54            }
55        }
56    };
57}
58
59// Use UTC
60
61#[rustfmt::skip]
62create_timezone! {
63    /// Universal Time Coordinated - Standard Time
64    #[default]
65    UTC, "Z", "Universal Time Coordinated", true, 0, 0,
66
67    // North America
68    /// Eastern Standard Time
69    EST, "EST", "Eastern Standard Time", false, 5, 0,
70    /// Eastern Daylight Time
71    EDT, "EDT", "Eastern Daylight Time", false, 4, 0,
72    /// Central Standard Time
73    CST, "CST", "Central Standard Time", false, 6, 0,
74    /// Central Daylight Time
75    CDT, "CDT", "Central Daylight Time", false, 5, 0,
76    /// Mountain Standard Time
77    MST, "MST", "Mountain Standard Time", false, 7, 0,
78    /// Mountain Daylight Time
79    MDT, "MDT", "Mountain Daylight Time", false, 6, 0,
80    /// Pacific Standard Time
81    PST, "PST", "Pacific Standard Time", false, 8, 0,
82    /// Pacific Daylight Time
83    PDT, "PDT", "Pacific Daylight Time", false, 7, 0,
84    /// Alaska Standard Time
85    AST, "AST", "Alaska Standard Time", false, 9, 0,
86    /// Alaska Daylight Time
87    AKDT, "AKDT", "Alaska Daylight Time", false, 8, 0,
88    /// Hawaii Standard Time
89    HST, "HST", "Hawaii Standard Time", false, 10, 0,
90    /// Hawaii-Aleutian Standard Time
91    HAST, "HAST", "Hawaii-Aleutian Standard Time", false, 10, 0,
92
93    // South America
94    /// Brasília Time
95    BRT, "BRT", "Brasília Time", false, 3, 0,
96    /// Argentina Time
97    ART, "ART", "Argentina Time", false, 3, 0,
98    /// Chile Standard Time
99    CLT, "CLT", "Chile Standard Time", false, 4, 0,
100    /// Chile Summer Time
101    CLST, "CLST", "Chile Summer Time", false, 3, 0,
102    /// Paraguay Time
103    PYT, "PYT", "Paraguay Time", false, 4, 0,
104    /// Paraguay Summer Time
105    PYST, "PYST", "Paraguay Summer Time", false, 3, 0,
106    /// French Guiana Time
107    GFT, "GFT", "French Guiana Time", false, 3, 0,
108    /// Venezuela Time
109    VET, "VET", "Venezuela Time", false, 4, 0,
110    /// Bolivia Time
111    BOT, "BOT", "Bolivia Time", false, 4, 0,
112    /// Peru Time
113    PET, "PET", "Peru Time", false, 5, 0,
114    /// Colombia Time
115    COT, "COT", "Colombia Time", false, 5, 0,
116    /// Ecuador Time
117    ECT, "ECT", "Ecuador Time", false, 5, 0,
118
119    // Europe
120    /// Greenwich Mean Time
121    GMT, "GMT", "Greenwich Mean Time", true, 0, 0,
122    /// British Summer Time
123    BST, "BST", "British Summer Time", true, 1, 0,
124    /// Western European Time
125    WET, "WET", "Western European Time", true, 0, 0,
126    /// Western European Summer Time
127    WEST, "WEST", "Western European Summer Time", true, 1, 0,
128    /// Central European Time
129    CET, "CET", "Central European Time", true, 1, 0,
130    /// Central European Summer Time
131    CEST, "CEST", "Central European Summer Time", true, 2, 0,
132    /// Eastern European Time
133    EET, "EET", "Eastern European Time", true, 2, 0,
134    /// Eastern European Summer Time
135    EEST, "EEST", "Eastern European Summer Time", true, 3, 0,
136    /// Moscow Standard Time
137    MSK, "MSK", "Moscow Standard Time", true, 3, 0,
138    /// Turkey Time
139    TRT, "TRT", "Turkey Time", true, 3, 0,
140    /// Irish Standard Time
141    IST, "IST", "Irish Standard Time", true, 1, 0,
142
143    // Africa
144    /// West Africa Time
145    WAT, "WAT", "West Africa Time", true, 1, 0,
146    /// Central Africa Time
147    CAT, "CAT", "Central Africa Time", true, 2, 0,
148    /// East Africa Time
149    EAT, "EAT", "East Africa Time", true, 3, 0,
150    /// South Africa Standard Time
151    SAST, "SAST", "South Africa Standard Time", true, 2, 0,
152
153    // Asia
154    /// India Standard Time
155    INST, "IST", "India Standard Time", true, 5, 30,
156    /// Pakistan Standard Time
157    PKT, "PKT", "Pakistan Standard Time", true, 5, 0,
158    /// Bangladesh Standard Time
159    BAST, "BST", "Bangladesh Standard Time", true, 6, 0,
160    /// Myanmar Time
161    MMT, "MMT", "Myanmar Time", true, 6, 30,
162    /// China Standard Time
163    CHST, "CST", "China Standard Time", true, 8, 0,
164    /// Japan Standard Time
165    JST, "JST", "Japan Standard Time", true, 9, 0,
166    /// Korea Standard Time
167    KST, "KST", "Korea Standard Time", true, 9, 0,
168    /// Singapore Time
169    SGT, "SGT", "Singapore Time", true, 8, 0,
170    /// Philippine Time
171    PHT, "PHT", "Philippine Time", true, 8, 0,
172    /// Indochina Time
173    ICT, "ICT", "Indochina Time", true, 7, 0,
174    /// Western Indonesia Time
175    WIB, "WIB", "Western Indonesia Time", true, 7, 0,
176    /// Central Indonesia Time
177    WITA, "WITA", "Central Indonesia Time", true, 8, 0,
178    /// Eastern Indonesia Time
179    WIT, "WIT", "Eastern Indonesia Time", true, 9, 0,
180    /// Gulf Standard Time
181    GST, "GST", "Gulf Standard Time", true, 4, 0,
182    /// Azerbaijan Time
183    AZT, "AZT", "Azerbaijan Time", true, 4, 0,
184    /// Georgia Standard Time
185    GET, "GET", "Georgia Standard Time", true, 4, 0,
186    /// Armenia Time
187    AMT, "AMT", "Armenia Time", true, 4, 0,
188    /// Arabia Standard Time
189    ARST, "AST", "Arabia Standard Time", true, 3, 0,
190    /// Eastern European Summer Time
191    EAEST, "EEST", "Eastern European Summer Time", true, 3, 0,
192
193    // Oceania
194    /// Australian Western Standard Time
195    AWST, "AWST", "Australian Western Standard Time", true, 8, 0,
196    /// Australian Central Standard Time
197    ACST, "ACST", "Australian Central Standard Time", true, 9, 30,
198    /// Australian Eastern Standard Time
199    AEST, "AEST", "Australian Eastern Standard Time", true, 10, 0,
200    /// Australian Central Daylight Time
201    ACDT, "ACDT", "Australian Central Daylight Time", true, 10, 30,
202    /// Australian Eastern Daylight Time
203    AEDT, "AEDT", "Australian Eastern Daylight Time", true, 11, 0,
204    /// New Zealand Standard Time
205    NZST, "NZST", "New Zealand Standard Time", true, 12, 0,
206    /// New Zealand Daylight Time
207    NZDT, "NZDT", "New Zealand Daylight Time", true, 13, 0,
208    /// Fiji Time
209    FJT, "FJT", "Fiji Time", true, 12, 0,
210    /// Chatham Standard Time
211    CHAST, "CHAST", "Chatham Standard Time", true, 12, 45,
212    /// Chatham Daylight Time
213    CHADT, "CHADT", "Chatham Daylight Time", true, 13, 45
214}