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