1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::translate::*;
use crate::TimeType;

crate::wrapper! {
    /// [`TimeZone`][crate::TimeZone] is an opaque structure whose members cannot be accessed
    /// directly.
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct TimeZone(Shared<ffi::GTimeZone>);

    match fn {
        ref => |ptr| ffi::g_time_zone_ref(ptr),
        unref => |ptr| ffi::g_time_zone_unref(ptr),
        type_ => || ffi::g_time_zone_get_type(),
    }
}

impl TimeZone {
    /// A version of `g_time_zone_new_identifier()` which returns the UTC time zone
    /// if `identifier` could not be parsed or loaded.
    ///
    /// If you need to check whether `identifier` was loaded successfully, use
    /// `g_time_zone_new_identifier()`.
    ///
    /// # Deprecated since 2.68
    ///
    /// Use `g_time_zone_new_identifier()` instead, as it provides
    ///  error reporting. Change your code to handle a potentially [`None`] return
    ///  value.
    /// ## `identifier`
    /// a timezone identifier
    ///
    /// # Returns
    ///
    /// the requested timezone
    #[cfg_attr(feature = "v2_68", deprecated = "Since 2.68")]
    #[doc(alias = "g_time_zone_new")]
    pub fn new(identifier: Option<&str>) -> TimeZone {
        unsafe { from_glib_full(ffi::g_time_zone_new(identifier.to_glib_none().0)) }
    }

    /// Creates a [`TimeZone`][crate::TimeZone] corresponding to local time. The local time
    /// zone may change between invocations to this function; for example,
    /// if the system administrator changes it.
    ///
    /// This is equivalent to calling [`new()`][Self::new()] with the value of
    /// the `TZ` environment variable (including the possibility of [`None`]).
    ///
    /// You should release the return value by calling `g_time_zone_unref()`
    /// when you are done with it.
    ///
    /// # Returns
    ///
    /// the local timezone
    #[doc(alias = "g_time_zone_new_local")]
    pub fn new_local() -> TimeZone {
        unsafe { from_glib_full(ffi::g_time_zone_new_local()) }
    }

    /// Creates a [`TimeZone`][crate::TimeZone] corresponding to the given constant offset from UTC,
    /// in seconds.
    ///
    /// This is equivalent to calling [`new()`][Self::new()] with a string in the form
    /// `[+|-]hh[:mm[:ss]]`.
    /// ## `seconds`
    /// offset to UTC, in seconds
    ///
    /// # Returns
    ///
    /// a timezone at the given offset from UTC
    #[cfg(any(feature = "v2_58", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_58")))]
    #[doc(alias = "g_time_zone_new_offset")]
    pub fn new_offset(seconds: i32) -> TimeZone {
        unsafe { from_glib_full(ffi::g_time_zone_new_offset(seconds)) }
    }

    /// Creates a [`TimeZone`][crate::TimeZone] corresponding to UTC.
    ///
    /// This is equivalent to calling [`new()`][Self::new()] with a value like
    /// "Z", "UTC", "+00", etc.
    ///
    /// You should release the return value by calling `g_time_zone_unref()`
    /// when you are done with it.
    ///
    /// # Returns
    ///
    /// the universal timezone
    #[doc(alias = "g_time_zone_new_utc")]
    pub fn new_utc() -> TimeZone {
        unsafe { from_glib_full(ffi::g_time_zone_new_utc()) }
    }

    /// Finds an interval within `self` that corresponds to the given `time_`.
    /// The meaning of `time_` depends on `type_`.
    ///
    /// If `type_` is [`TimeType::Universal`][crate::TimeType::Universal] then this function will always
    /// succeed (since universal time is monotonic and continuous).
    ///
    /// Otherwise `time_` is treated as local time. The distinction between
    /// [`TimeType::Standard`][crate::TimeType::Standard] and [`TimeType::Daylight`][crate::TimeType::Daylight] is ignored except in
    /// the case that the given `time_` is ambiguous. In Toronto, for example,
    /// 01:30 on November 7th 2010 occurred twice (once inside of daylight
    /// savings time and the next, an hour later, outside of daylight savings
    /// time). In this case, the different value of `type_` would result in a
    /// different interval being returned.
    ///
    /// It is still possible for this function to fail. In Toronto, for
    /// example, 02:00 on March 14th 2010 does not exist (due to the leap
    /// forward to begin daylight savings time). -1 is returned in that
    /// case.
    /// ## `type_`
    /// the [`TimeType`][crate::TimeType] of `time_`
    /// ## `time_`
    /// a number of seconds since January 1, 1970
    ///
    /// # Returns
    ///
    /// the interval containing `time_`, or -1 in case of failure
    #[doc(alias = "g_time_zone_find_interval")]
    pub fn find_interval(&self, type_: TimeType, time_: i64) -> i32 {
        unsafe { ffi::g_time_zone_find_interval(self.to_glib_none().0, type_.into_glib(), time_) }
    }

    /// Determines the time zone abbreviation to be used during a particular
    /// `interval` of time in the time zone `self`.
    ///
    /// For example, in Toronto this is currently "EST" during the winter
    /// months and "EDT" during the summer months when daylight savings time
    /// is in effect.
    /// ## `interval`
    /// an interval within the timezone
    ///
    /// # Returns
    ///
    /// the time zone abbreviation, which belongs to `self`
    #[doc(alias = "g_time_zone_get_abbreviation")]
    #[doc(alias = "get_abbreviation")]
    pub fn abbreviation(&self, interval: i32) -> crate::GString {
        unsafe {
            from_glib_none(ffi::g_time_zone_get_abbreviation(
                self.to_glib_none().0,
                interval,
            ))
        }
    }

    /// Get the identifier of this [`TimeZone`][crate::TimeZone], as passed to [`new()`][Self::new()].
    /// If the identifier passed at construction time was not recognised, `UTC` will
    /// be returned. If it was [`None`], the identifier of the local timezone at
    /// construction time will be returned.
    ///
    /// The identifier will be returned in the same format as provided at
    /// construction time: if provided as a time offset, that will be returned by
    /// this function.
    ///
    /// # Returns
    ///
    /// identifier for this timezone
    #[cfg(any(feature = "v2_58", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_58")))]
    #[doc(alias = "g_time_zone_get_identifier")]
    #[doc(alias = "get_identifier")]
    pub fn identifier(&self) -> crate::GString {
        unsafe { from_glib_none(ffi::g_time_zone_get_identifier(self.to_glib_none().0)) }
    }

    /// Determines the offset to UTC in effect during a particular `interval`
    /// of time in the time zone `self`.
    ///
    /// The offset is the number of seconds that you add to UTC time to
    /// arrive at local time for `self` (ie: negative numbers for time zones
    /// west of GMT, positive numbers for east).
    /// ## `interval`
    /// an interval within the timezone
    ///
    /// # Returns
    ///
    /// the number of seconds that should be added to UTC to get the
    ///  local time in `self`
    #[doc(alias = "g_time_zone_get_offset")]
    #[doc(alias = "get_offset")]
    pub fn offset(&self, interval: i32) -> i32 {
        unsafe { ffi::g_time_zone_get_offset(self.to_glib_none().0, interval) }
    }

    /// Determines if daylight savings time is in effect during a particular
    /// `interval` of time in the time zone `self`.
    /// ## `interval`
    /// an interval within the timezone
    ///
    /// # Returns
    ///
    /// [`true`] if daylight savings time is in effect
    #[doc(alias = "g_time_zone_is_dst")]
    pub fn is_dst(&self, interval: i32) -> bool {
        unsafe { from_glib(ffi::g_time_zone_is_dst(self.to_glib_none().0, interval)) }
    }
}

unsafe impl Send for TimeZone {}
unsafe impl Sync for TimeZone {}