glib/auto/time_zone.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{TimeType, ffi, translate::*};
6
7crate::wrapper! {
8 /// ), and cannot be
9 /// passed to `GLib::TimeZone::new()`.
10 ///
11 /// Every UTC time is contained within exactly one interval, but a given
12 /// local time may be contained within zero, one or two intervals (due to
13 /// incontinuities associated with daylight savings time).
14 ///
15 /// An interval may refer to a specific period of time (eg: the duration
16 /// of daylight savings time during 2010) or it may refer to many periods
17 /// of time that share the same properties (eg: all periods of daylight
18 /// savings time). It is also possible (usually for political reasons)
19 /// that some properties (like the abbreviation) change between intervals
20 /// without other properties changing.
21 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
22 pub struct TimeZone(Shared<ffi::GTimeZone>);
23
24 match fn {
25 ref => |ptr| ffi::g_time_zone_ref(ptr),
26 unref => |ptr| ffi::g_time_zone_unref(ptr),
27 type_ => || ffi::g_time_zone_get_type(),
28 }
29}
30
31impl TimeZone {
32 /// A version of g_time_zone_new_identifier() which returns the UTC time zone
33 /// if @identifier could not be parsed or loaded.
34 ///
35 /// If you need to check whether @identifier was loaded successfully, use
36 /// g_time_zone_new_identifier().
37 ///
38 /// # Deprecated since 2.68
39 ///
40 /// Use g_time_zone_new_identifier() instead, as it provides
41 /// error reporting. Change your code to handle a potentially [`None`] return
42 /// value.
43 /// ## `identifier`
44 /// a timezone identifier
45 ///
46 /// # Returns
47 ///
48 /// the requested timezone
49 #[cfg_attr(feature = "v2_68", deprecated = "Since 2.68")]
50 #[allow(deprecated)]
51 #[doc(alias = "g_time_zone_new")]
52 pub fn new(identifier: Option<&str>) -> TimeZone {
53 unsafe { from_glib_full(ffi::g_time_zone_new(identifier.to_glib_none().0)) }
54 }
55
56 /// 5.6](http://tools.ietf.org/html/rfc3339#section-5.6)
57 /// for a precise definition of valid RFC3339 time offsets
58 /// (the `time-offset` expansion) and ISO 8601 for the
59 /// full list of valid time offsets. See
60 /// [The GNU C Library manual](http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html)
61 /// for an explanation of the possible
62 /// values of the `TZ` environment variable. See
63 /// [Microsoft Time Zone Index Values](http://msdn.microsoft.com/en-us/library/ms912391`28v`=winembedded.11`29`)
64 /// for the list of time zones on Windows.
65 ///
66 /// You should release the return value by calling g_time_zone_unref()
67 /// when you are done with it.
68 /// ## `identifier`
69 /// a timezone identifier
70 ///
71 /// # Returns
72 ///
73 /// the requested timezone, or [`None`] on
74 /// failure
75 #[cfg(feature = "v2_68")]
76 #[cfg_attr(docsrs, doc(cfg(feature = "v2_68")))]
77 #[doc(alias = "g_time_zone_new_identifier")]
78 #[doc(alias = "new_identifier")]
79 pub fn from_identifier(identifier: Option<&str>) -> Option<TimeZone> {
80 unsafe { from_glib_full(ffi::g_time_zone_new_identifier(identifier.to_glib_none().0)) }
81 }
82
83 /// Creates a #GTimeZone corresponding to local time. The local time
84 /// zone may change between invocations to this function; for example,
85 /// if the system administrator changes it.
86 ///
87 /// This is equivalent to calling g_time_zone_new() with the value of
88 /// the `TZ` environment variable (including the possibility of [`None`]).
89 ///
90 /// You should release the return value by calling g_time_zone_unref()
91 /// when you are done with it.
92 ///
93 /// # Returns
94 ///
95 /// the local timezone
96 #[doc(alias = "g_time_zone_new_local")]
97 #[doc(alias = "new_local")]
98 pub fn local() -> TimeZone {
99 unsafe { from_glib_full(ffi::g_time_zone_new_local()) }
100 }
101
102 /// Creates a #GTimeZone corresponding to the given constant offset from UTC,
103 /// in seconds.
104 ///
105 /// This is equivalent to calling g_time_zone_new() with a string in the form
106 /// `[+|-]hh[:mm[:ss]]`.
107 ///
108 /// It is possible for this function to fail if @seconds is too big (greater than
109 /// 24 hours), in which case this function will return the UTC timezone for
110 /// backwards compatibility. To detect failures like this, use
111 /// g_time_zone_new_identifier() directly.
112 /// ## `seconds`
113 /// offset to UTC, in seconds
114 ///
115 /// # Returns
116 ///
117 /// a timezone at the given offset from UTC, or UTC on
118 /// failure
119 #[cfg(feature = "v2_58")]
120 #[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))]
121 #[doc(alias = "g_time_zone_new_offset")]
122 #[doc(alias = "new_offset")]
123 pub fn from_offset(seconds: i32) -> TimeZone {
124 unsafe { from_glib_full(ffi::g_time_zone_new_offset(seconds)) }
125 }
126
127 /// Creates a #GTimeZone corresponding to UTC.
128 ///
129 /// This is equivalent to calling g_time_zone_new() with a value like
130 /// "Z", "UTC", "+00", etc.
131 ///
132 /// You should release the return value by calling g_time_zone_unref()
133 /// when you are done with it.
134 ///
135 /// # Returns
136 ///
137 /// the universal timezone
138 #[doc(alias = "g_time_zone_new_utc")]
139 #[doc(alias = "new_utc")]
140 pub fn utc() -> TimeZone {
141 unsafe { from_glib_full(ffi::g_time_zone_new_utc()) }
142 }
143
144 /// Finds an interval within @self that corresponds to the given @time_.
145 /// The meaning of @time_ depends on @type_.
146 ///
147 /// If @type_ is [`TimeType::Universal`][crate::TimeType::Universal] then this function will always
148 /// succeed (since universal time is monotonic and continuous).
149 ///
150 /// Otherwise @time_ is treated as local time. The distinction between
151 /// [`TimeType::Standard`][crate::TimeType::Standard] and [`TimeType::Daylight`][crate::TimeType::Daylight] is ignored except in
152 /// the case that the given @time_ is ambiguous. In Toronto, for example,
153 /// 01:30 on November 7th 2010 occurred twice (once inside of daylight
154 /// savings time and the next, an hour later, outside of daylight savings
155 /// time). In this case, the different value of @type_ would result in a
156 /// different interval being returned.
157 ///
158 /// It is still possible for this function to fail. In Toronto, for
159 /// example, 02:00 on March 14th 2010 does not exist (due to the leap
160 /// forward to begin daylight savings time). -1 is returned in that
161 /// case.
162 /// ## `type_`
163 /// the #GTimeType of @time_
164 /// ## `time_`
165 /// a number of seconds since January 1, 1970
166 ///
167 /// # Returns
168 ///
169 /// the interval containing @time_, or -1 in case of failure
170 #[doc(alias = "g_time_zone_find_interval")]
171 pub fn find_interval(&self, type_: TimeType, time_: i64) -> i32 {
172 unsafe { ffi::g_time_zone_find_interval(self.to_glib_none().0, type_.into_glib(), time_) }
173 }
174
175 /// Determines the time zone abbreviation to be used during a particular
176 /// @interval of time in the time zone @self.
177 ///
178 /// For example, in Toronto this is currently "EST" during the winter
179 /// months and "EDT" during the summer months when daylight savings time
180 /// is in effect.
181 /// ## `interval`
182 /// an interval within the timezone
183 ///
184 /// # Returns
185 ///
186 /// the time zone abbreviation, which belongs to @self
187 #[doc(alias = "g_time_zone_get_abbreviation")]
188 #[doc(alias = "get_abbreviation")]
189 pub fn abbreviation(&self, interval: i32) -> crate::GString {
190 unsafe {
191 from_glib_none(ffi::g_time_zone_get_abbreviation(
192 self.to_glib_none().0,
193 interval,
194 ))
195 }
196 }
197
198 /// Get the identifier of this #GTimeZone, as passed to g_time_zone_new().
199 /// If the identifier passed at construction time was not recognised, `UTC` will
200 /// be returned. If it was [`None`], the identifier of the local timezone at
201 /// construction time will be returned.
202 ///
203 /// The identifier will be returned in the same format as provided at
204 /// construction time: if provided as a time offset, that will be returned by
205 /// this function.
206 ///
207 /// # Returns
208 ///
209 /// identifier for this timezone
210 #[cfg(feature = "v2_58")]
211 #[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))]
212 #[doc(alias = "g_time_zone_get_identifier")]
213 #[doc(alias = "get_identifier")]
214 pub fn identifier(&self) -> crate::GString {
215 unsafe { from_glib_none(ffi::g_time_zone_get_identifier(self.to_glib_none().0)) }
216 }
217
218 /// Determines the offset to UTC in effect during a particular @interval
219 /// of time in the time zone @self.
220 ///
221 /// The offset is the number of seconds that you add to UTC time to
222 /// arrive at local time for @self (ie: negative numbers for time zones
223 /// west of GMT, positive numbers for east).
224 /// ## `interval`
225 /// an interval within the timezone
226 ///
227 /// # Returns
228 ///
229 /// the number of seconds that should be added to UTC to get the
230 /// local time in @self
231 #[doc(alias = "g_time_zone_get_offset")]
232 #[doc(alias = "get_offset")]
233 pub fn offset(&self, interval: i32) -> i32 {
234 unsafe { ffi::g_time_zone_get_offset(self.to_glib_none().0, interval) }
235 }
236
237 /// Determines if daylight savings time is in effect during a particular
238 /// @interval of time in the time zone @self.
239 /// ## `interval`
240 /// an interval within the timezone
241 ///
242 /// # Returns
243 ///
244 /// [`true`] if daylight savings time is in effect
245 #[doc(alias = "g_time_zone_is_dst")]
246 pub fn is_dst(&self, interval: i32) -> bool {
247 unsafe { from_glib(ffi::g_time_zone_is_dst(self.to_glib_none().0, interval)) }
248 }
249}
250
251unsafe impl Send for TimeZone {}
252unsafe impl Sync for TimeZone {}