cap_time_ext/
timezone.rs

1use ambient_authority::AmbientAuthority;
2use iana_time_zone::get_timezone;
3
4/// A reference to a timezone resource.
5pub struct Timezone(());
6
7/// An error type returned by `Timezone::timezone_name`.
8#[derive(Debug)]
9pub struct TimezoneError(String);
10
11impl std::error::Error for TimezoneError {}
12
13impl std::fmt::Display for TimezoneError {
14    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15        self.0.fmt(f)
16    }
17}
18
19impl Timezone {
20    /// Constructs a new instance of `Self`.
21    ///
22    /// # Ambient Authority
23    ///
24    /// This uses ambient authority to accesses clocks.
25    #[inline]
26    pub const fn new(ambient_authority: AmbientAuthority) -> Self {
27        let _ = ambient_authority;
28        Self(())
29    }
30
31    /// Returns the combined date and time with timezone.
32    ///
33    /// Converts NaiveTime to DateTime
34    #[inline]
35    pub fn timezone_name(&self) -> Result<String, TimezoneError> {
36        get_timezone().map_err(|e| TimezoneError(e.to_string()))
37    }
38}