grid_tariffs/
timezone.rs

1use serde::Serialize;
2
3#[derive(Debug, Clone, Copy, Serialize)]
4#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5#[allow(dead_code)]
6pub enum Timezone {
7    Utc,
8    Stockholm,
9}
10pub use Timezone::*;
11
12impl Timezone {
13    pub const fn to_tz(self) -> chrono_tz::Tz
14    where
15        chrono_tz::Tz: Sized + Copy,
16    {
17        use chrono_tz::{Europe, UTC};
18        match self {
19            Utc => UTC,
20            Stockholm => Europe::Stockholm,
21        }
22    }
23}
24
25#[cfg(test)]
26impl Timezone {
27    pub fn dt(
28        &self,
29        year: i32,
30        month: u32,
31        day: u32,
32        hour: u32,
33        minute: u32,
34        second: u32,
35    ) -> chrono::DateTime<chrono_tz::Tz> {
36        use chrono::TimeZone;
37        let tz = self.to_tz();
38        tz.with_ymd_and_hms(year, month, day, hour, minute, second)
39            .unwrap()
40    }
41}
42
43impl From<Timezone> for chrono_tz::Tz {
44    fn from(timezone: Timezone) -> Self {
45        timezone.to_tz()
46    }
47}