Skip to main content

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    // rustdoc-stripper-ignore-next-stop
22    /// ), and cannot be
23    /// passed to `GLib::TimeZone::new()`.
24    ///
25    /// Every UTC time is contained within exactly one interval, but a given
26    /// local time may be contained within zero, one or two intervals (due to
27    /// incontinuities associated with daylight savings time).
28    ///
29    /// An interval may refer to a specific period of time (eg: the duration
30    /// of daylight savings time during 2010) or it may refer to many periods
31    /// of time that share the same properties (eg: all periods of daylight
32    /// savings time).  It is also possible (usually for political reasons)
33    /// that some properties (like the abbreviation) change between intervals
34    /// without other properties changing.
35    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
36    pub struct TimeZone(Shared<ffi::GTimeZone>);
37
38    match fn {
39        ref => |ptr| ffi::g_time_zone_ref(ptr),
40        unref => |ptr| ffi::g_time_zone_unref(ptr),
41        type_ => || ffi::g_time_zone_get_type(),
42    }
43}
44
45impl TimeZone {
46    /// A version of g_time_zone_new_identifier() which returns the UTC time zone
47    /// if @identifier could not be parsed or loaded.
48    ///
49    /// If you need to check whether @identifier was loaded successfully, use
50    /// g_time_zone_new_identifier().
51    ///
52    /// # Deprecated since 2.68
53    ///
54    /// Use g_time_zone_new_identifier() instead, as it provides
55    ///     error reporting. Change your code to handle a potentially [`None`] return
56    ///     value.
57    /// ## `identifier`
58    /// a timezone identifier
59    ///
60    /// # Returns
61    ///
62    /// the requested timezone
63    // rustdoc-stripper-ignore-next-stop
64    /// A version of g_time_zone_new_identifier() which returns the UTC time zone
65    /// if @identifier could not be parsed or loaded.
66    ///
67    /// If you need to check whether @identifier was loaded successfully, use
68    /// g_time_zone_new_identifier().
69    ///
70    /// # Deprecated since 2.68
71    ///
72    /// Use g_time_zone_new_identifier() instead, as it provides
73    ///     error reporting. Change your code to handle a potentially [`None`] return
74    ///     value.
75    /// ## `identifier`
76    /// a timezone identifier
77    ///
78    /// # Returns
79    ///
80    /// the requested timezone
81    #[cfg_attr(feature = "v2_68", deprecated = "Since 2.68")]
82    #[allow(deprecated)]
83    #[doc(alias = "g_time_zone_new")]
84    pub fn new(identifier: Option<&str>) -> TimeZone {
85        unsafe { from_glib_full(ffi::g_time_zone_new(identifier.to_glib_none().0)) }
86    }
87
88    /// 5.6](http://tools.ietf.org/html/rfc3339#section-5.6)
89    /// for a precise definition of valid RFC3339 time offsets
90    /// (the `time-offset` expansion) and ISO 8601 for the
91    /// full list of valid time offsets.  See
92    /// [The GNU C Library manual](http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html)
93    /// for an explanation of the possible
94    /// values of the `TZ` environment variable. See
95    /// [Microsoft Time Zone Index Values](http://msdn.microsoft.com/en-us/library/ms912391`28v`=winembedded.11`29`)
96    /// for the list of time zones on Windows.
97    ///
98    /// You should release the return value by calling g_time_zone_unref()
99    /// when you are done with it.
100    /// ## `identifier`
101    /// a timezone identifier
102    ///
103    /// # Returns
104    ///
105    /// the requested timezone, or [`None`] on
106    ///     failure
107    // rustdoc-stripper-ignore-next-stop
108    /// 5.6](http://tools.ietf.org/html/rfc3339#section-5.6)
109    /// for a precise definition of valid RFC3339 time offsets
110    /// (the `time-offset` expansion) and ISO 8601 for the
111    /// full list of valid time offsets.  See
112    /// [The GNU C Library manual](http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html)
113    /// for an explanation of the possible
114    /// values of the `TZ` environment variable. See
115    /// [Microsoft Time Zone Index Values](http://msdn.microsoft.com/en-us/library/ms912391`28v`=winembedded.11`29`)
116    /// for the list of time zones on Windows.
117    ///
118    /// You should release the return value by calling g_time_zone_unref()
119    /// when you are done with it.
120    /// ## `identifier`
121    /// a timezone identifier
122    ///
123    /// # Returns
124    ///
125    /// the requested timezone, or [`None`] on
126    ///     failure
127    #[cfg(feature = "v2_68")]
128    #[cfg_attr(docsrs, doc(cfg(feature = "v2_68")))]
129    #[doc(alias = "g_time_zone_new_identifier")]
130    #[doc(alias = "new_identifier")]
131    pub fn from_identifier(identifier: Option<&str>) -> Option<TimeZone> {
132        unsafe { from_glib_full(ffi::g_time_zone_new_identifier(identifier.to_glib_none().0)) }
133    }
134
135    /// Creates a #GTimeZone corresponding to local time.  The local time
136    /// zone may change between invocations to this function; for example,
137    /// if the system administrator changes it.
138    ///
139    /// This is equivalent to calling g_time_zone_new() with the value of
140    /// the `TZ` environment variable (including the possibility of [`None`]).
141    ///
142    /// You should release the return value by calling g_time_zone_unref()
143    /// when you are done with it.
144    ///
145    /// # Returns
146    ///
147    /// the local timezone
148    // rustdoc-stripper-ignore-next-stop
149    /// Creates a #GTimeZone corresponding to local time.  The local time
150    /// zone may change between invocations to this function; for example,
151    /// if the system administrator changes it.
152    ///
153    /// This is equivalent to calling g_time_zone_new() with the value of
154    /// the `TZ` environment variable (including the possibility of [`None`]).
155    ///
156    /// You should release the return value by calling g_time_zone_unref()
157    /// when you are done with it.
158    ///
159    /// # Returns
160    ///
161    /// the local timezone
162    #[doc(alias = "g_time_zone_new_local")]
163    #[doc(alias = "new_local")]
164    pub fn local() -> TimeZone {
165        unsafe { from_glib_full(ffi::g_time_zone_new_local()) }
166    }
167
168    /// Creates a #GTimeZone corresponding to the given constant offset from UTC,
169    /// in seconds.
170    ///
171    /// This is equivalent to calling g_time_zone_new() with a string in the form
172    /// `[+|-]hh[:mm[:ss]]`.
173    ///
174    /// It is possible for this function to fail if @seconds is too big (greater than
175    /// 24 hours), in which case this function will return the UTC timezone for
176    /// backwards compatibility. To detect failures like this, use
177    /// g_time_zone_new_identifier() directly.
178    /// ## `seconds`
179    /// offset to UTC, in seconds
180    ///
181    /// # Returns
182    ///
183    /// a timezone at the given offset from UTC, or UTC on
184    ///   failure
185    // rustdoc-stripper-ignore-next-stop
186    /// Creates a #GTimeZone corresponding to the given constant offset from UTC,
187    /// in seconds.
188    ///
189    /// This is equivalent to calling g_time_zone_new() with a string in the form
190    /// `[+|-]hh[:mm[:ss]]`.
191    ///
192    /// It is possible for this function to fail if @seconds is too big (greater than
193    /// 24 hours), in which case this function will return the UTC timezone for
194    /// backwards compatibility. To detect failures like this, use
195    /// g_time_zone_new_identifier() directly.
196    /// ## `seconds`
197    /// offset to UTC, in seconds
198    ///
199    /// # Returns
200    ///
201    /// a timezone at the given offset from UTC, or UTC on
202    ///   failure
203    #[cfg(feature = "v2_58")]
204    #[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))]
205    #[doc(alias = "g_time_zone_new_offset")]
206    #[doc(alias = "new_offset")]
207    pub fn from_offset(seconds: i32) -> TimeZone {
208        unsafe { from_glib_full(ffi::g_time_zone_new_offset(seconds)) }
209    }
210
211    /// Creates a #GTimeZone corresponding to UTC.
212    ///
213    /// This is equivalent to calling g_time_zone_new() with a value like
214    /// "Z", "UTC", "+00", etc.
215    ///
216    /// You should release the return value by calling g_time_zone_unref()
217    /// when you are done with it.
218    ///
219    /// # Returns
220    ///
221    /// the universal timezone
222    // rustdoc-stripper-ignore-next-stop
223    /// Creates a #GTimeZone corresponding to UTC.
224    ///
225    /// This is equivalent to calling g_time_zone_new() with a value like
226    /// "Z", "UTC", "+00", etc.
227    ///
228    /// You should release the return value by calling g_time_zone_unref()
229    /// when you are done with it.
230    ///
231    /// # Returns
232    ///
233    /// the universal timezone
234    #[doc(alias = "g_time_zone_new_utc")]
235    #[doc(alias = "new_utc")]
236    pub fn utc() -> TimeZone {
237        unsafe { from_glib_full(ffi::g_time_zone_new_utc()) }
238    }
239
240    /// Finds an interval within @self that corresponds to the given @time_.
241    /// The meaning of @time_ depends on @type_.
242    ///
243    /// If @type_ is [`TimeType::Universal`][crate::TimeType::Universal] then this function will always
244    /// succeed (since universal time is monotonic and continuous).
245    ///
246    /// Otherwise @time_ is treated as local time.  The distinction between
247    /// [`TimeType::Standard`][crate::TimeType::Standard] and [`TimeType::Daylight`][crate::TimeType::Daylight] is ignored except in
248    /// the case that the given @time_ is ambiguous.  In Toronto, for example,
249    /// 01:30 on November 7th 2010 occurred twice (once inside of daylight
250    /// savings time and the next, an hour later, outside of daylight savings
251    /// time).  In this case, the different value of @type_ would result in a
252    /// different interval being returned.
253    ///
254    /// It is still possible for this function to fail.  In Toronto, for
255    /// example, 02:00 on March 14th 2010 does not exist (due to the leap
256    /// forward to begin daylight savings time).  -1 is returned in that
257    /// case.
258    /// ## `type_`
259    /// the #GTimeType of @time_
260    /// ## `time_`
261    /// a number of seconds since January 1, 1970
262    ///
263    /// # Returns
264    ///
265    /// the interval containing @time_, or -1 in case of failure
266    // rustdoc-stripper-ignore-next-stop
267    /// Finds an interval within @self that corresponds to the given @time_.
268    /// The meaning of @time_ depends on @type_.
269    ///
270    /// If @type_ is [`TimeType::Universal`][crate::TimeType::Universal] then this function will always
271    /// succeed (since universal time is monotonic and continuous).
272    ///
273    /// Otherwise @time_ is treated as local time.  The distinction between
274    /// [`TimeType::Standard`][crate::TimeType::Standard] and [`TimeType::Daylight`][crate::TimeType::Daylight] is ignored except in
275    /// the case that the given @time_ is ambiguous.  In Toronto, for example,
276    /// 01:30 on November 7th 2010 occurred twice (once inside of daylight
277    /// savings time and the next, an hour later, outside of daylight savings
278    /// time).  In this case, the different value of @type_ would result in a
279    /// different interval being returned.
280    ///
281    /// It is still possible for this function to fail.  In Toronto, for
282    /// example, 02:00 on March 14th 2010 does not exist (due to the leap
283    /// forward to begin daylight savings time).  -1 is returned in that
284    /// case.
285    /// ## `type_`
286    /// the #GTimeType of @time_
287    /// ## `time_`
288    /// a number of seconds since January 1, 1970
289    ///
290    /// # Returns
291    ///
292    /// the interval containing @time_, or -1 in case of failure
293    #[doc(alias = "g_time_zone_find_interval")]
294    pub fn find_interval(&self, type_: TimeType, time_: i64) -> i32 {
295        unsafe { ffi::g_time_zone_find_interval(self.to_glib_none().0, type_.into_glib(), time_) }
296    }
297
298    /// Determines the time zone abbreviation to be used during a particular
299    /// @interval of time in the time zone @self.
300    ///
301    /// For example, in Toronto this is currently "EST" during the winter
302    /// months and "EDT" during the summer months when daylight savings time
303    /// is in effect.
304    /// ## `interval`
305    /// an interval within the timezone
306    ///
307    /// # Returns
308    ///
309    /// the time zone abbreviation, which belongs to @self
310    // rustdoc-stripper-ignore-next-stop
311    /// Determines the time zone abbreviation to be used during a particular
312    /// @interval of time in the time zone @self.
313    ///
314    /// For example, in Toronto this is currently "EST" during the winter
315    /// months and "EDT" during the summer months when daylight savings time
316    /// is in effect.
317    /// ## `interval`
318    /// an interval within the timezone
319    ///
320    /// # Returns
321    ///
322    /// the time zone abbreviation, which belongs to @self
323    #[doc(alias = "g_time_zone_get_abbreviation")]
324    #[doc(alias = "get_abbreviation")]
325    pub fn abbreviation(&self, interval: i32) -> crate::GString {
326        unsafe {
327            from_glib_none(ffi::g_time_zone_get_abbreviation(
328                self.to_glib_none().0,
329                interval,
330            ))
331        }
332    }
333
334    /// Get the identifier of this #GTimeZone, as passed to g_time_zone_new().
335    /// If the identifier passed at construction time was not recognised, `UTC` will
336    /// be returned. If it was [`None`], the identifier of the local timezone at
337    /// construction time will be returned.
338    ///
339    /// The identifier will be returned in the same format as provided at
340    /// construction time: if provided as a time offset, that will be returned by
341    /// this function.
342    ///
343    /// # Returns
344    ///
345    /// identifier for this timezone
346    // rustdoc-stripper-ignore-next-stop
347    /// Get the identifier of this #GTimeZone, as passed to g_time_zone_new().
348    /// If the identifier passed at construction time was not recognised, `UTC` will
349    /// be returned. If it was [`None`], the identifier of the local timezone at
350    /// construction time will be returned.
351    ///
352    /// The identifier will be returned in the same format as provided at
353    /// construction time: if provided as a time offset, that will be returned by
354    /// this function.
355    ///
356    /// # Returns
357    ///
358    /// identifier for this timezone
359    #[cfg(feature = "v2_58")]
360    #[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))]
361    #[doc(alias = "g_time_zone_get_identifier")]
362    #[doc(alias = "get_identifier")]
363    pub fn identifier(&self) -> crate::GString {
364        unsafe { from_glib_none(ffi::g_time_zone_get_identifier(self.to_glib_none().0)) }
365    }
366
367    /// Determines the offset to UTC in effect during a particular @interval
368    /// of time in the time zone @self.
369    ///
370    /// The offset is the number of seconds that you add to UTC time to
371    /// arrive at local time for @self (ie: negative numbers for time zones
372    /// west of GMT, positive numbers for east).
373    /// ## `interval`
374    /// an interval within the timezone
375    ///
376    /// # Returns
377    ///
378    /// the number of seconds that should be added to UTC to get the
379    ///          local time in @self
380    // rustdoc-stripper-ignore-next-stop
381    /// Determines the offset to UTC in effect during a particular @interval
382    /// of time in the time zone @self.
383    ///
384    /// The offset is the number of seconds that you add to UTC time to
385    /// arrive at local time for @self (ie: negative numbers for time zones
386    /// west of GMT, positive numbers for east).
387    /// ## `interval`
388    /// an interval within the timezone
389    ///
390    /// # Returns
391    ///
392    /// the number of seconds that should be added to UTC to get the
393    ///          local time in @self
394    #[doc(alias = "g_time_zone_get_offset")]
395    #[doc(alias = "get_offset")]
396    pub fn offset(&self, interval: i32) -> i32 {
397        unsafe { ffi::g_time_zone_get_offset(self.to_glib_none().0, interval) }
398    }
399
400    /// Determines if daylight savings time is in effect during a particular
401    /// @interval of time in the time zone @self.
402    /// ## `interval`
403    /// an interval within the timezone
404    ///
405    /// # Returns
406    ///
407    /// [`true`] if daylight savings time is in effect
408    // rustdoc-stripper-ignore-next-stop
409    /// Determines if daylight savings time is in effect during a particular
410    /// @interval of time in the time zone @self.
411    /// ## `interval`
412    /// an interval within the timezone
413    ///
414    /// # Returns
415    ///
416    /// [`true`] if daylight savings time is in effect
417    #[doc(alias = "g_time_zone_is_dst")]
418    pub fn is_dst(&self, interval: i32) -> bool {
419        unsafe { from_glib(ffi::g_time_zone_is_dst(self.to_glib_none().0, interval)) }
420    }
421}
422
423unsafe impl Send for TimeZone {}
424unsafe impl Sync for TimeZone {}