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::{ffi, translate::*, TimeType};
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 /// Creates a #GTimeZone corresponding to @identifier. If @identifier cannot be
70 /// parsed or loaded, [`None`] is returned.
71 ///
72 /// @identifier can either be an RFC3339/ISO 8601 time offset or
73 /// something that would pass as a valid value for the `TZ` environment
74 /// variable (including [`None`]).
75 ///
76 /// In Windows, @identifier can also be the unlocalized name of a time
77 /// zone for standard time, for example "Pacific Standard Time".
78 ///
79 /// Valid RFC3339 time offsets are `"Z"` (for UTC) or
80 /// `"±hh:mm"`. ISO 8601 additionally specifies
81 /// `"±hhmm"` and `"±hh"`. Offsets are
82 /// time values to be added to Coordinated Universal Time (UTC) to get
83 /// the local time.
84 ///
85 /// In UNIX, the `TZ` environment variable typically corresponds
86 /// to the name of a file in the zoneinfo database, an absolute path to a file
87 /// somewhere else, or a string in
88 /// "std offset [dst [offset],start[/time],end[/time]]" (POSIX) format.
89 /// There are no spaces in the specification. The name of standard
90 /// and daylight savings time zone must be three or more alphabetic
91 /// characters. Offsets are time values to be added to local time to
92 /// get Coordinated Universal Time (UTC) and should be
93 /// `"[±]hh[[:]mm[:ss]]"`. Dates are either
94 /// `"Jn"` (Julian day with n between 1 and 365, leap
95 /// years not counted), `"n"` (zero-based Julian day
96 /// with n between 0 and 365) or `"Mm.w.d"` (day d
97 /// (0 <= d <= 6) of week w (1 <= w <= 5) of month m (1 <= m <= 12), day
98 /// 0 is a Sunday). Times are in local wall clock time, the default is
99 /// 02:00:00.
100 ///
101 /// In Windows, the "tzn[+|–]hh[:mm[:ss]][dzn]" format is used, but also
102 /// accepts POSIX format. The Windows format uses US rules for all time
103 /// zones; daylight savings time is 60 minutes behind the standard time
104 /// with date and time of change taken from Pacific Standard Time.
105 /// Offsets are time values to be added to the local time to get
106 /// Coordinated Universal Time (UTC).
107 ///
108 /// g_time_zone_new_local() calls this function with the value of the
109 /// `TZ` environment variable. This function itself is independent of
110 /// the value of `TZ`, but if @identifier is [`None`] then `/etc/localtime`
111 /// will be consulted to discover the correct time zone on UNIX and the
112 /// registry will be consulted or GetTimeZoneInformation() will be used
113 /// to get the local time zone on Windows.
114 ///
115 /// If intervals are not available, only time zone rules from `TZ`
116 /// environment variable or other means, then they will be computed
117 /// from year 1900 to 2037. If the maximum year for the rules is
118 /// available and it is greater than 2037, then it will followed
119 /// instead.
120 ///
121 /// See
122 /// [RFC3339 §5.6](http://tools.ietf.org/html/rfc3339#section-5.6)
123 /// for a precise definition of valid RFC3339 time offsets
124 /// (the `time-offset` expansion) and ISO 8601 for the
125 /// full list of valid time offsets. See
126 /// [The GNU C Library manual](http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html)
127 /// for an explanation of the possible
128 /// values of the `TZ` environment variable. See
129 /// [Microsoft Time Zone Index Values](http://msdn.microsoft.com/en-us/library/ms912391`28v`=winembedded.11`29`)
130 /// for the list of time zones on Windows.
131 ///
132 /// You should release the return value by calling g_time_zone_unref()
133 /// when you are done with it.
134 /// ## `identifier`
135 /// a timezone identifier
136 ///
137 /// # Returns
138 ///
139 /// the requested timezone, or [`None`] on
140 /// failure
141 #[cfg(feature = "v2_68")]
142 #[cfg_attr(docsrs, doc(cfg(feature = "v2_68")))]
143 #[doc(alias = "g_time_zone_new_identifier")]
144 #[doc(alias = "new_identifier")]
145 pub fn from_identifier(identifier: Option<&str>) -> Option<TimeZone> {
146 unsafe { from_glib_full(ffi::g_time_zone_new_identifier(identifier.to_glib_none().0)) }
147 }
148
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 #[cfg(feature = "v2_58")]
186 #[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))]
187 #[doc(alias = "g_time_zone_new_offset")]
188 #[doc(alias = "new_offset")]
189 pub fn from_offset(seconds: i32) -> TimeZone {
190 unsafe { from_glib_full(ffi::g_time_zone_new_offset(seconds)) }
191 }
192
193 /// Creates a #GTimeZone corresponding to UTC.
194 ///
195 /// This is equivalent to calling g_time_zone_new() with a value like
196 /// "Z", "UTC", "+00", etc.
197 ///
198 /// You should release the return value by calling g_time_zone_unref()
199 /// when you are done with it.
200 ///
201 /// # Returns
202 ///
203 /// the universal timezone
204 #[doc(alias = "g_time_zone_new_utc")]
205 #[doc(alias = "new_utc")]
206 pub fn utc() -> TimeZone {
207 unsafe { from_glib_full(ffi::g_time_zone_new_utc()) }
208 }
209
210 /// Finds an interval within @self that corresponds to the given @time_.
211 /// The meaning of @time_ depends on @type_.
212 ///
213 /// If @type_ is [`TimeType::Universal`][crate::TimeType::Universal] then this function will always
214 /// succeed (since universal time is monotonic and continuous).
215 ///
216 /// Otherwise @time_ is treated as local time. The distinction between
217 /// [`TimeType::Standard`][crate::TimeType::Standard] and [`TimeType::Daylight`][crate::TimeType::Daylight] is ignored except in
218 /// the case that the given @time_ is ambiguous. In Toronto, for example,
219 /// 01:30 on November 7th 2010 occurred twice (once inside of daylight
220 /// savings time and the next, an hour later, outside of daylight savings
221 /// time). In this case, the different value of @type_ would result in a
222 /// different interval being returned.
223 ///
224 /// It is still possible for this function to fail. In Toronto, for
225 /// example, 02:00 on March 14th 2010 does not exist (due to the leap
226 /// forward to begin daylight savings time). -1 is returned in that
227 /// case.
228 /// ## `type_`
229 /// the #GTimeType of @time_
230 /// ## `time_`
231 /// a number of seconds since January 1, 1970
232 ///
233 /// # Returns
234 ///
235 /// the interval containing @time_, or -1 in case of failure
236 #[doc(alias = "g_time_zone_find_interval")]
237 pub fn find_interval(&self, type_: TimeType, time_: i64) -> i32 {
238 unsafe { ffi::g_time_zone_find_interval(self.to_glib_none().0, type_.into_glib(), time_) }
239 }
240
241 /// Determines the time zone abbreviation to be used during a particular
242 /// @interval of time in the time zone @self.
243 ///
244 /// For example, in Toronto this is currently "EST" during the winter
245 /// months and "EDT" during the summer months when daylight savings time
246 /// is in effect.
247 /// ## `interval`
248 /// an interval within the timezone
249 ///
250 /// # Returns
251 ///
252 /// the time zone abbreviation, which belongs to @self
253 #[doc(alias = "g_time_zone_get_abbreviation")]
254 #[doc(alias = "get_abbreviation")]
255 pub fn abbreviation(&self, interval: i32) -> crate::GString {
256 unsafe {
257 from_glib_none(ffi::g_time_zone_get_abbreviation(
258 self.to_glib_none().0,
259 interval,
260 ))
261 }
262 }
263
264 /// Get the identifier of this #GTimeZone, as passed to g_time_zone_new().
265 /// If the identifier passed at construction time was not recognised, `UTC` will
266 /// be returned. If it was [`None`], the identifier of the local timezone at
267 /// construction time will be returned.
268 ///
269 /// The identifier will be returned in the same format as provided at
270 /// construction time: if provided as a time offset, that will be returned by
271 /// this function.
272 ///
273 /// # Returns
274 ///
275 /// identifier for this timezone
276 #[cfg(feature = "v2_58")]
277 #[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))]
278 #[doc(alias = "g_time_zone_get_identifier")]
279 #[doc(alias = "get_identifier")]
280 pub fn identifier(&self) -> crate::GString {
281 unsafe { from_glib_none(ffi::g_time_zone_get_identifier(self.to_glib_none().0)) }
282 }
283
284 /// Determines the offset to UTC in effect during a particular @interval
285 /// of time in the time zone @self.
286 ///
287 /// The offset is the number of seconds that you add to UTC time to
288 /// arrive at local time for @self (ie: negative numbers for time zones
289 /// west of GMT, positive numbers for east).
290 /// ## `interval`
291 /// an interval within the timezone
292 ///
293 /// # Returns
294 ///
295 /// the number of seconds that should be added to UTC to get the
296 /// local time in @self
297 #[doc(alias = "g_time_zone_get_offset")]
298 #[doc(alias = "get_offset")]
299 pub fn offset(&self, interval: i32) -> i32 {
300 unsafe { ffi::g_time_zone_get_offset(self.to_glib_none().0, interval) }
301 }
302
303 /// Determines if daylight savings time is in effect during a particular
304 /// @interval of time in the time zone @self.
305 /// ## `interval`
306 /// an interval within the timezone
307 ///
308 /// # Returns
309 ///
310 /// [`true`] if daylight savings time is in effect
311 #[doc(alias = "g_time_zone_is_dst")]
312 pub fn is_dst(&self, interval: i32) -> bool {
313 unsafe { from_glib(ffi::g_time_zone_is_dst(self.to_glib_none().0, interval)) }
314 }
315}
316
317unsafe impl Send for TimeZone {}
318unsafe impl Sync for TimeZone {}