Skip to main content

glib/auto/
date_time.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::{BoolError, TimeSpan, TimeZone, ffi, translate::*};
6
7crate::wrapper! {
8    /// `GDateTime` is a structure that combines a Gregorian date and time
9    /// into a single structure.
10    ///
11    /// `GDateTime` provides many conversion and methods to manipulate dates and times.
12    /// Time precision is provided down to microseconds and the time can range
13    /// (proleptically) from 0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999.
14    /// `GDateTime` follows POSIX time in the sense that it is oblivious to leap
15    /// seconds.
16    ///
17    /// `GDateTime` is an immutable object; once it has been created it cannot
18    /// be modified further. All modifiers will create a new `GDateTime`.
19    /// Nearly all such functions can fail due to the date or time going out
20    /// of range, in which case [`None`] will be returned.
21    ///
22    /// `GDateTime` is reference counted: the reference count is increased by calling
23    /// `GLib::DateTime::ref()` and decreased by calling `GLib::DateTime::unref()`.
24    /// When the reference count drops to 0, the resources allocated by the `GDateTime`
25    /// structure are released.
26    ///
27    /// Many parts of the API may produce non-obvious results. As an
28    /// example, adding two months to January 31st will yield March 31st
29    /// whereas adding one month and then one month again will yield either
30    /// March 28th or March 29th.  Also note that adding 24 hours is not
31    /// always the same as adding one day (since days containing daylight
32    /// savings time transitions are either 23 or 25 hours in length).
33    #[derive(Debug)]
34    pub struct DateTime(Shared<ffi::GDateTime>);
35
36    match fn {
37        ref => |ptr| ffi::g_date_time_ref(ptr),
38        unref => |ptr| ffi::g_date_time_unref(ptr),
39        type_ => || ffi::g_date_time_get_type(),
40    }
41}
42
43impl DateTime {
44    /// Creates a new #GDateTime corresponding to the given date and time in
45    /// the time zone @tz.
46    ///
47    /// The @year must be between 1 and 9999, @month between 1 and 12 and @day
48    /// between 1 and 28, 29, 30 or 31 depending on the month and the year.
49    ///
50    /// @hour must be between 0 and 23 and @minute must be between 0 and 59.
51    ///
52    /// @seconds must be at least 0.0 and must be strictly less than 60.0.
53    /// It will be rounded down to the nearest microsecond.
54    ///
55    /// If the given time is not representable in the given time zone (for
56    /// example, 02:30 on March 14th 2010 in Toronto, due to daylight savings
57    /// time) then the time will be rounded up to the nearest existing time
58    /// (in this case, 03:00).  If this matters to you then you should verify
59    /// the return value for containing the same as the numbers you gave.
60    ///
61    /// In the case that the given time is ambiguous in the given time zone
62    /// (for example, 01:30 on November 7th 2010 in Toronto, due to daylight
63    /// savings time) then the time falling within standard (ie:
64    /// non-daylight) time is taken.
65    ///
66    /// It not considered a programmer error for the values to this function
67    /// to be out of range, but in the case that they are, the function will
68    /// return [`None`].
69    ///
70    /// You should release the return value by calling g_date_time_unref()
71    /// when you are done with it.
72    /// ## `tz`
73    /// a #GTimeZone
74    /// ## `year`
75    /// the year component of the date
76    /// ## `month`
77    /// the month component of the date
78    /// ## `day`
79    /// the day component of the date
80    /// ## `hour`
81    /// the hour component of the date
82    /// ## `minute`
83    /// the minute component of the date
84    /// ## `seconds`
85    /// the number of seconds past the minute
86    ///
87    /// # Returns
88    ///
89    /// a new #GDateTime, or [`None`]
90    #[doc(alias = "g_date_time_new")]
91    pub fn new(
92        tz: &TimeZone,
93        year: i32,
94        month: i32,
95        day: i32,
96        hour: i32,
97        minute: i32,
98        seconds: f64,
99    ) -> Result<DateTime, BoolError> {
100        unsafe {
101            Option::<_>::from_glib_full(ffi::g_date_time_new(
102                tz.to_glib_none().0,
103                year,
104                month,
105                day,
106                hour,
107                minute,
108                seconds,
109            ))
110            .ok_or_else(|| crate::bool_error!("Invalid date"))
111        }
112    }
113
114    /// Creates a #GDateTime corresponding to the given
115    /// [ISO 8601 formatted string](https://en.wikipedia.org/wiki/ISO_8601)
116    /// @text. ISO 8601 strings of the form `<date><sep><time><tz>` are supported, with
117    /// some extensions from [RFC 3339](https://tools.ietf.org/html/rfc3339) as
118    /// mentioned below.
119    ///
120    /// Note that as #GDateTime "is oblivious to leap seconds", leap seconds information
121    /// in an ISO-8601 string will be ignored, so a `23:59:60` time would be parsed as
122    /// `23:59:59`.
123    ///
124    /// `<sep>` is the separator and can be either 'T', 't' or ' '. The latter two
125    /// separators are an extension from
126    /// [RFC 3339](https://tools.ietf.org/html/rfc3339#section-5.6).
127    ///
128    /// `<date>` is in the form:
129    ///
130    /// - `YYYY-MM-DD` - Year/month/day, e.g. 2016-08-24.
131    /// - `YYYYMMDD` - Same as above without dividers.
132    /// - `YYYY-DDD` - Ordinal day where DDD is from 001 to 366, e.g. 2016-237.
133    /// - `YYYYDDD` - Same as above without dividers.
134    /// - `YYYY-Www-D` - Week day where ww is from 01 to 52 and D from 1-7,
135    ///   e.g. 2016-W34-3.
136    /// - `YYYYWwwD` - Same as above without dividers.
137    ///
138    /// `<time>` is in the form:
139    ///
140    /// - `hh:mm:ss(.sss)` - Hours, minutes, seconds (subseconds), e.g. 22:10:42.123.
141    /// - `hhmmss(.sss)` - Same as above without dividers.
142    ///
143    /// `<tz>` is an optional timezone suffix of the form:
144    ///
145    /// - `Z` - UTC.
146    /// - `+hh:mm` or `-hh:mm` - Offset from UTC in hours and minutes, e.g. +12:00.
147    /// - `+hh` or `-hh` - Offset from UTC in hours, e.g. +12.
148    ///
149    /// If the timezone is not provided in @text it must be provided in @default_tz
150    /// (this field is otherwise ignored).
151    ///
152    /// This call can fail (returning [`None`]) if @text is not a valid ISO 8601
153    /// formatted string.
154    ///
155    /// You should release the return value by calling g_date_time_unref()
156    /// when you are done with it.
157    /// ## `text`
158    /// an ISO 8601 formatted time string.
159    /// ## `default_tz`
160    /// a #GTimeZone to use if the text doesn't contain a
161    ///                          timezone, or [`None`].
162    ///
163    /// # Returns
164    ///
165    /// a new #GDateTime, or [`None`]
166    #[doc(alias = "g_date_time_new_from_iso8601")]
167    #[doc(alias = "new_from_iso8601")]
168    pub fn from_iso8601(text: &str, default_tz: Option<&TimeZone>) -> Result<DateTime, BoolError> {
169        unsafe {
170            Option::<_>::from_glib_full(ffi::g_date_time_new_from_iso8601(
171                text.to_glib_none().0,
172                default_tz.to_glib_none().0,
173            ))
174            .ok_or_else(|| crate::bool_error!("Invalid date"))
175        }
176    }
177
178    //#[cfg_attr(feature = "v2_62", deprecated = "Since 2.62")]
179    //#[allow(deprecated)]
180    //#[doc(alias = "g_date_time_new_from_timeval_local")]
181    //#[doc(alias = "new_from_timeval_local")]
182    //pub fn from_timeval_local(tv: /*Ignored*/&TimeVal) -> Result<DateTime, BoolError> {
183    //    unsafe { TODO: call ffi:g_date_time_new_from_timeval_local() }
184    //}
185
186    //#[cfg_attr(feature = "v2_62", deprecated = "Since 2.62")]
187    //#[allow(deprecated)]
188    //#[doc(alias = "g_date_time_new_from_timeval_utc")]
189    //#[doc(alias = "new_from_timeval_utc")]
190    //pub fn from_timeval_utc(tv: /*Ignored*/&TimeVal) -> Result<DateTime, BoolError> {
191    //    unsafe { TODO: call ffi:g_date_time_new_from_timeval_utc() }
192    //}
193
194    /// Creates a #GDateTime corresponding to the given Unix time @t in the
195    /// local time zone.
196    ///
197    /// Unix time is the number of seconds that have elapsed since 1970-01-01
198    /// 00:00:00 UTC, regardless of the local time offset.
199    ///
200    /// This call can fail (returning [`None`]) if @t represents a time outside
201    /// of the supported range of #GDateTime.
202    ///
203    /// You should release the return value by calling g_date_time_unref()
204    /// when you are done with it.
205    /// ## `t`
206    /// the Unix time
207    ///
208    /// # Returns
209    ///
210    /// a new #GDateTime, or [`None`]
211    #[doc(alias = "g_date_time_new_from_unix_local")]
212    #[doc(alias = "new_from_unix_local")]
213    pub fn from_unix_local(t: i64) -> Result<DateTime, BoolError> {
214        unsafe {
215            Option::<_>::from_glib_full(ffi::g_date_time_new_from_unix_local(t))
216                .ok_or_else(|| crate::bool_error!("Invalid date"))
217        }
218    }
219
220    /// Creates a [`DateTime`][crate::DateTime] corresponding to the given Unix time @t in the
221    /// local time zone.
222    ///
223    /// Unix time is the number of microseconds that have elapsed since 1970-01-01
224    /// 00:00:00 UTC, regardless of the local time offset.
225    ///
226    /// This call can fail (returning `NULL`) if @t represents a time outside
227    /// of the supported range of #GDateTime.
228    ///
229    /// You should release the return value by calling `GLib::DateTime::unref()`
230    /// when you are done with it.
231    /// ## `usecs`
232    /// the Unix time in microseconds
233    ///
234    /// # Returns
235    ///
236    /// a new [`DateTime`][crate::DateTime], or `NULL`
237    #[cfg(feature = "v2_80")]
238    #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
239    #[doc(alias = "g_date_time_new_from_unix_local_usec")]
240    #[doc(alias = "new_from_unix_local_usec")]
241    pub fn from_unix_local_usec(usecs: i64) -> Result<DateTime, BoolError> {
242        unsafe {
243            Option::<_>::from_glib_full(ffi::g_date_time_new_from_unix_local_usec(usecs))
244                .ok_or_else(|| crate::bool_error!("Invalid date"))
245        }
246    }
247
248    /// Creates a #GDateTime corresponding to the given Unix time @t in UTC.
249    ///
250    /// Unix time is the number of seconds that have elapsed since 1970-01-01
251    /// 00:00:00 UTC.
252    ///
253    /// This call can fail (returning [`None`]) if @t represents a time outside
254    /// of the supported range of #GDateTime.
255    ///
256    /// You should release the return value by calling g_date_time_unref()
257    /// when you are done with it.
258    /// ## `t`
259    /// the Unix time
260    ///
261    /// # Returns
262    ///
263    /// a new #GDateTime, or [`None`]
264    #[doc(alias = "g_date_time_new_from_unix_utc")]
265    #[doc(alias = "new_from_unix_utc")]
266    pub fn from_unix_utc(t: i64) -> Result<DateTime, BoolError> {
267        unsafe {
268            Option::<_>::from_glib_full(ffi::g_date_time_new_from_unix_utc(t))
269                .ok_or_else(|| crate::bool_error!("Invalid date"))
270        }
271    }
272
273    /// Creates a [`DateTime`][crate::DateTime] corresponding to the given Unix time @t in UTC.
274    ///
275    /// Unix time is the number of microseconds that have elapsed since 1970-01-01
276    /// 00:00:00 UTC.
277    ///
278    /// This call can fail (returning `NULL`) if @t represents a time outside
279    /// of the supported range of #GDateTime.
280    ///
281    /// You should release the return value by calling `GLib::DateTime::unref()`
282    /// when you are done with it.
283    /// ## `usecs`
284    /// the Unix time in microseconds
285    ///
286    /// # Returns
287    ///
288    /// a new [`DateTime`][crate::DateTime], or `NULL`
289    #[cfg(feature = "v2_80")]
290    #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
291    #[doc(alias = "g_date_time_new_from_unix_utc_usec")]
292    #[doc(alias = "new_from_unix_utc_usec")]
293    pub fn from_unix_utc_usec(usecs: i64) -> Result<DateTime, BoolError> {
294        unsafe {
295            Option::<_>::from_glib_full(ffi::g_date_time_new_from_unix_utc_usec(usecs))
296                .ok_or_else(|| crate::bool_error!("Invalid date"))
297        }
298    }
299
300    /// Creates a new #GDateTime corresponding to the given date and time in
301    /// the local time zone.
302    ///
303    /// This call is equivalent to calling g_date_time_new() with the time
304    /// zone returned by g_time_zone_new_local().
305    /// ## `year`
306    /// the year component of the date
307    /// ## `month`
308    /// the month component of the date
309    /// ## `day`
310    /// the day component of the date
311    /// ## `hour`
312    /// the hour component of the date
313    /// ## `minute`
314    /// the minute component of the date
315    /// ## `seconds`
316    /// the number of seconds past the minute
317    ///
318    /// # Returns
319    ///
320    /// a #GDateTime, or [`None`]
321    #[doc(alias = "g_date_time_new_local")]
322    #[doc(alias = "new_local")]
323    pub fn from_local(
324        year: i32,
325        month: i32,
326        day: i32,
327        hour: i32,
328        minute: i32,
329        seconds: f64,
330    ) -> Result<DateTime, BoolError> {
331        unsafe {
332            Option::<_>::from_glib_full(ffi::g_date_time_new_local(
333                year, month, day, hour, minute, seconds,
334            ))
335            .ok_or_else(|| crate::bool_error!("Invalid date"))
336        }
337    }
338
339    /// Creates a #GDateTime corresponding to this exact instant in the given
340    /// time zone @tz.  The time is as accurate as the system allows, to a
341    /// maximum accuracy of 1 microsecond.
342    ///
343    /// This function will always succeed unless GLib is still being used after the
344    /// year 9999.
345    ///
346    /// You should release the return value by calling g_date_time_unref()
347    /// when you are done with it.
348    /// ## `tz`
349    /// a #GTimeZone
350    ///
351    /// # Returns
352    ///
353    /// a new #GDateTime, or [`None`]
354    #[doc(alias = "g_date_time_new_now")]
355    #[doc(alias = "new_now")]
356    pub fn now(tz: &TimeZone) -> Result<DateTime, BoolError> {
357        unsafe {
358            Option::<_>::from_glib_full(ffi::g_date_time_new_now(tz.to_glib_none().0))
359                .ok_or_else(|| crate::bool_error!("Invalid date"))
360        }
361    }
362
363    /// Creates a #GDateTime corresponding to this exact instant in the local
364    /// time zone.
365    ///
366    /// This is equivalent to calling g_date_time_new_now() with the time
367    /// zone returned by g_time_zone_new_local().
368    ///
369    /// # Returns
370    ///
371    /// a new #GDateTime, or [`None`]
372    #[doc(alias = "g_date_time_new_now_local")]
373    #[doc(alias = "new_now_local")]
374    pub fn now_local() -> Result<DateTime, BoolError> {
375        unsafe {
376            Option::<_>::from_glib_full(ffi::g_date_time_new_now_local())
377                .ok_or_else(|| crate::bool_error!("Invalid date"))
378        }
379    }
380
381    /// Creates a #GDateTime corresponding to this exact instant in UTC.
382    ///
383    /// This is equivalent to calling g_date_time_new_now() with the time
384    /// zone returned by g_time_zone_new_utc().
385    ///
386    /// # Returns
387    ///
388    /// a new #GDateTime, or [`None`]
389    #[doc(alias = "g_date_time_new_now_utc")]
390    #[doc(alias = "new_now_utc")]
391    pub fn now_utc() -> Result<DateTime, BoolError> {
392        unsafe {
393            Option::<_>::from_glib_full(ffi::g_date_time_new_now_utc())
394                .ok_or_else(|| crate::bool_error!("Invalid date"))
395        }
396    }
397
398    /// Creates a new #GDateTime corresponding to the given date and time in
399    /// UTC.
400    ///
401    /// This call is equivalent to calling g_date_time_new() with the time
402    /// zone returned by g_time_zone_new_utc().
403    /// ## `year`
404    /// the year component of the date
405    /// ## `month`
406    /// the month component of the date
407    /// ## `day`
408    /// the day component of the date
409    /// ## `hour`
410    /// the hour component of the date
411    /// ## `minute`
412    /// the minute component of the date
413    /// ## `seconds`
414    /// the number of seconds past the minute
415    ///
416    /// # Returns
417    ///
418    /// a #GDateTime, or [`None`]
419    #[doc(alias = "g_date_time_new_utc")]
420    #[doc(alias = "new_utc")]
421    pub fn from_utc(
422        year: i32,
423        month: i32,
424        day: i32,
425        hour: i32,
426        minute: i32,
427        seconds: f64,
428    ) -> Result<DateTime, BoolError> {
429        unsafe {
430            Option::<_>::from_glib_full(ffi::g_date_time_new_utc(
431                year, month, day, hour, minute, seconds,
432            ))
433            .ok_or_else(|| crate::bool_error!("Invalid date"))
434        }
435    }
436
437    /// Creates a copy of @self and adds the specified timespan to the copy.
438    /// ## `timespan`
439    /// a #GTimeSpan
440    ///
441    /// # Returns
442    ///
443    /// the newly created #GDateTime which
444    ///   should be freed with g_date_time_unref(), or [`None`]
445    #[doc(alias = "g_date_time_add")]
446    pub fn add(&self, timespan: TimeSpan) -> Result<DateTime, BoolError> {
447        unsafe {
448            Option::<_>::from_glib_full(ffi::g_date_time_add(
449                self.to_glib_none().0,
450                timespan.into_glib(),
451            ))
452            .ok_or_else(|| crate::bool_error!("Invalid date"))
453        }
454    }
455
456    /// Creates a copy of @self and adds the specified number of days to the
457    /// copy. Add negative values to subtract days.
458    /// ## `days`
459    /// the number of days
460    ///
461    /// # Returns
462    ///
463    /// the newly created #GDateTime which
464    ///   should be freed with g_date_time_unref(), or [`None`]
465    #[doc(alias = "g_date_time_add_days")]
466    pub fn add_days(&self, days: i32) -> Result<DateTime, BoolError> {
467        unsafe {
468            Option::<_>::from_glib_full(ffi::g_date_time_add_days(self.to_glib_none().0, days))
469                .ok_or_else(|| crate::bool_error!("Invalid date"))
470        }
471    }
472
473    /// Creates a new #GDateTime adding the specified values to the current date and
474    /// time in @self. Add negative values to subtract.
475    /// ## `years`
476    /// the number of years to add
477    /// ## `months`
478    /// the number of months to add
479    /// ## `days`
480    /// the number of days to add
481    /// ## `hours`
482    /// the number of hours to add
483    /// ## `minutes`
484    /// the number of minutes to add
485    /// ## `seconds`
486    /// the number of seconds to add
487    ///
488    /// # Returns
489    ///
490    /// the newly created #GDateTime which
491    ///   should be freed with g_date_time_unref(), or [`None`]
492    #[doc(alias = "g_date_time_add_full")]
493    pub fn add_full(
494        &self,
495        years: i32,
496        months: i32,
497        days: i32,
498        hours: i32,
499        minutes: i32,
500        seconds: f64,
501    ) -> Result<DateTime, BoolError> {
502        unsafe {
503            Option::<_>::from_glib_full(ffi::g_date_time_add_full(
504                self.to_glib_none().0,
505                years,
506                months,
507                days,
508                hours,
509                minutes,
510                seconds,
511            ))
512            .ok_or_else(|| crate::bool_error!("Invalid date"))
513        }
514    }
515
516    /// Creates a copy of @self and adds the specified number of hours.
517    /// Add negative values to subtract hours.
518    /// ## `hours`
519    /// the number of hours to add
520    ///
521    /// # Returns
522    ///
523    /// the newly created #GDateTime which
524    ///   should be freed with g_date_time_unref(), or [`None`]
525    #[doc(alias = "g_date_time_add_hours")]
526    pub fn add_hours(&self, hours: i32) -> Result<DateTime, BoolError> {
527        unsafe {
528            Option::<_>::from_glib_full(ffi::g_date_time_add_hours(self.to_glib_none().0, hours))
529                .ok_or_else(|| crate::bool_error!("Invalid date"))
530        }
531    }
532
533    /// Creates a copy of @self adding the specified number of minutes.
534    /// Add negative values to subtract minutes.
535    /// ## `minutes`
536    /// the number of minutes to add
537    ///
538    /// # Returns
539    ///
540    /// the newly created #GDateTime which
541    ///   should be freed with g_date_time_unref(), or [`None`]
542    #[doc(alias = "g_date_time_add_minutes")]
543    pub fn add_minutes(&self, minutes: i32) -> Result<DateTime, BoolError> {
544        unsafe {
545            Option::<_>::from_glib_full(ffi::g_date_time_add_minutes(
546                self.to_glib_none().0,
547                minutes,
548            ))
549            .ok_or_else(|| crate::bool_error!("Invalid date"))
550        }
551    }
552
553    /// Creates a copy of @self and adds the specified number of months to the
554    /// copy. Add negative values to subtract months.
555    ///
556    /// The day of the month of the resulting #GDateTime is clamped to the number
557    /// of days in the updated calendar month. For example, if adding 1 month to
558    /// 31st January 2018, the result would be 28th February 2018. In 2020 (a leap
559    /// year), the result would be 29th February.
560    /// ## `months`
561    /// the number of months
562    ///
563    /// # Returns
564    ///
565    /// the newly created #GDateTime which
566    ///   should be freed with g_date_time_unref(), or [`None`]
567    #[doc(alias = "g_date_time_add_months")]
568    pub fn add_months(&self, months: i32) -> Result<DateTime, BoolError> {
569        unsafe {
570            Option::<_>::from_glib_full(ffi::g_date_time_add_months(self.to_glib_none().0, months))
571                .ok_or_else(|| crate::bool_error!("Invalid date"))
572        }
573    }
574
575    /// Creates a copy of @self and adds the specified number of seconds.
576    /// Add negative values to subtract seconds.
577    /// ## `seconds`
578    /// the number of seconds to add
579    ///
580    /// # Returns
581    ///
582    /// the newly created #GDateTime which
583    ///   should be freed with g_date_time_unref(), or [`None`]
584    #[doc(alias = "g_date_time_add_seconds")]
585    pub fn add_seconds(&self, seconds: f64) -> Result<DateTime, BoolError> {
586        unsafe {
587            Option::<_>::from_glib_full(ffi::g_date_time_add_seconds(
588                self.to_glib_none().0,
589                seconds,
590            ))
591            .ok_or_else(|| crate::bool_error!("Invalid date"))
592        }
593    }
594
595    /// Creates a copy of @self and adds the specified number of weeks to the
596    /// copy. Add negative values to subtract weeks.
597    /// ## `weeks`
598    /// the number of weeks
599    ///
600    /// # Returns
601    ///
602    /// the newly created #GDateTime which
603    ///   should be freed with g_date_time_unref(), or [`None`]
604    #[doc(alias = "g_date_time_add_weeks")]
605    pub fn add_weeks(&self, weeks: i32) -> Result<DateTime, BoolError> {
606        unsafe {
607            Option::<_>::from_glib_full(ffi::g_date_time_add_weeks(self.to_glib_none().0, weeks))
608                .ok_or_else(|| crate::bool_error!("Invalid date"))
609        }
610    }
611
612    /// Creates a copy of @self and adds the specified number of years to the
613    /// copy. Add negative values to subtract years.
614    ///
615    /// As with g_date_time_add_months(), if the resulting date would be 29th
616    /// February on a non-leap year, the day will be clamped to 28th February.
617    /// ## `years`
618    /// the number of years
619    ///
620    /// # Returns
621    ///
622    /// the newly created #GDateTime which
623    ///   should be freed with g_date_time_unref(), or [`None`]
624    #[doc(alias = "g_date_time_add_years")]
625    pub fn add_years(&self, years: i32) -> Result<DateTime, BoolError> {
626        unsafe {
627            Option::<_>::from_glib_full(ffi::g_date_time_add_years(self.to_glib_none().0, years))
628                .ok_or_else(|| crate::bool_error!("Invalid date"))
629        }
630    }
631
632    #[doc(alias = "g_date_time_compare")]
633    fn compare(&self, dt2: &DateTime) -> i32 {
634        unsafe {
635            ffi::g_date_time_compare(
636                ToGlibPtr::<*mut ffi::GDateTime>::to_glib_none(self).0 as ffi::gconstpointer,
637                ToGlibPtr::<*mut ffi::GDateTime>::to_glib_none(dt2).0 as ffi::gconstpointer,
638            )
639        }
640    }
641
642    /// Calculates the difference in time between @self and @begin.
643    ///
644    /// The time span that is returned is effectively @self - @begin (positive if the
645    /// first parameter is larger).
646    ///
647    /// This effectively converts both date-times to the same time zone before
648    /// calculating the difference.
649    /// ## `begin`
650    /// another date-time
651    ///
652    /// # Returns
653    ///
654    /// the difference between the two date-times, as a time
655    ///   span expressed in microseconds
656    #[doc(alias = "g_date_time_difference")]
657    pub fn difference(&self, begin: &DateTime) -> TimeSpan {
658        unsafe {
659            from_glib(ffi::g_date_time_difference(
660                self.to_glib_none().0,
661                begin.to_glib_none().0,
662            ))
663        }
664    }
665
666    #[doc(alias = "g_date_time_equal")]
667    fn equal(&self, dt2: &DateTime) -> bool {
668        unsafe {
669            from_glib(ffi::g_date_time_equal(
670                ToGlibPtr::<*mut ffi::GDateTime>::to_glib_none(self).0 as ffi::gconstpointer,
671                ToGlibPtr::<*mut ffi::GDateTime>::to_glib_none(dt2).0 as ffi::gconstpointer,
672            ))
673        }
674    }
675
676    /// Creates a newly allocated string representing the requested @format.
677    ///
678    /// The format strings understood by this function are a subset of the
679    /// `strftime()` format language as specified by C99.  The ``D``, ``U`` and ``W``
680    /// conversions are not supported, nor is the `E` modifier.  The GNU
681    /// extensions ``k``, ``l``, ``s`` and ``P`` are supported, however, as are the
682    /// `0`, `_` and `-` modifiers. The Python extension ``f`` is also supported.
683    ///
684    /// In contrast to `strftime()`, this function always produces a UTF-8
685    /// string, regardless of the current locale.  Note that the rendering of
686    /// many formats is locale-dependent and may not match the `strftime()`
687    /// output exactly.
688    ///
689    /// The following format specifiers are supported:
690    ///
691    /// - ``a``: the abbreviated weekday name according to the current locale
692    /// - ``A``: the full weekday name according to the current locale
693    /// - ``b``: the abbreviated month name according to the current locale
694    /// - ``B``: the full month name according to the current locale
695    /// - ``c``: the preferred date and time representation for the current locale
696    /// - ``C``: the century number (year/100) as a 2-digit integer (00-99)
697    /// - ``d``: the day of the month as a decimal number (range 01 to 31)
698    /// - ``e``: the day of the month as a decimal number (range 1 to 31);
699    ///   single digits are preceded by a figure space (U+2007)
700    /// - ``F``: equivalent to ``Y`-`m`-`d`` (the ISO 8601 date format)
701    /// - ``g``: the last two digits of the ISO 8601 week-based year as a
702    ///   decimal number (00-99). This works well with ``V`` and ``u``.
703    /// - ``G``: the ISO 8601 week-based year as a decimal number. This works
704    ///   well with ``V`` and ``u``.
705    /// - ``h``: equivalent to ``b``
706    /// - ``H``: the hour as a decimal number using a 24-hour clock (range 00 to 23)
707    /// - ``I``: the hour as a decimal number using a 12-hour clock (range 01 to 12)
708    /// - ``j``: the day of the year as a decimal number (range 001 to 366)
709    /// - ``k``: the hour (24-hour clock) as a decimal number (range 0 to 23);
710    ///   single digits are preceded by a figure space (U+2007)
711    /// - ``l``: the hour (12-hour clock) as a decimal number (range 1 to 12);
712    ///   single digits are preceded by a figure space (U+2007)
713    /// - ``m``: the month as a decimal number (range 01 to 12)
714    /// - ``M``: the minute as a decimal number (range 00 to 59)
715    /// - ``f``: the microsecond as a decimal number (range 000000 to 999999)
716    /// - ``p``: either ‘AM’ or ‘PM’ according to the given time value, or the
717    ///   corresponding  strings for the current locale.  Noon is treated as
718    ///   ‘PM’ and midnight as ‘AM’. Use of this format specifier is discouraged, as
719    ///   many locales have no concept of AM/PM formatting. Use ``c`` or ``X`` instead.
720    /// - ``P``: like ``p`` but lowercase: ‘am’ or ‘pm’ or a corresponding string for
721    ///   the current locale. Use of this format specifier is discouraged, as
722    ///   many locales have no concept of AM/PM formatting. Use ``c`` or ``X`` instead.
723    /// - ``r``: the time in a.m. or p.m. notation. Use of this format specifier is
724    ///   discouraged, as many locales have no concept of AM/PM formatting. Use ``c``
725    ///   or ``X`` instead.
726    /// - ``R``: the time in 24-hour notation (``H`:`M``)
727    /// - ``s``: the number of seconds since the Epoch, that is, since 1970-01-01
728    ///   00:00:00 UTC
729    /// - ``S``: the second as a decimal number (range 00 to 60)
730    /// - ``t``: a tab character
731    /// - ``T``: the time in 24-hour notation with seconds (``H`:`M`:`S``)
732    /// - ``u``: the ISO 8601 standard day of the week as a decimal, range 1 to 7,
733    ///    Monday being 1. This works well with ``G`` and ``V``.
734    /// - ``V``: the ISO 8601 standard week number of the current year as a decimal
735    ///   number, range 01 to 53, where week 1 is the first week that has at
736    ///   least 4 days in the new year. See g_date_time_get_week_of_year().
737    ///   This works well with ``G`` and ``u``.
738    /// - ``w``: the day of the week as a decimal, range 0 to 6, Sunday being 0.
739    ///   This is not the ISO 8601 standard format — use ``u`` instead.
740    /// - ``x``: the preferred date representation for the current locale without
741    ///   the time
742    /// - ``X``: the preferred time representation for the current locale without
743    ///   the date
744    /// - ``y``: the year as a decimal number without the century
745    /// - ``Y``: the year as a decimal number including the century
746    /// - ``z``: the time zone as an offset from UTC (`+hhmm`)
747    /// - `%:z`: the time zone as an offset from UTC (`+hh:mm`).
748    ///   This is a gnulib `strftime()` extension. Since: 2.38
749    /// - `%::z`: the time zone as an offset from UTC (`+hh:mm:ss`). This is a
750    ///   gnulib `strftime()` extension. Since: 2.38
751    /// - `%:::z`: the time zone as an offset from UTC, with `:` to necessary
752    ///   precision (e.g., `-04`, `+05:30`). This is a gnulib `strftime()` extension. Since: 2.38
753    /// - ``Z``: the time zone or name or abbreviation
754    /// - `%%`: a literal `%` character
755    ///
756    /// Some conversion specifications can be modified by preceding the
757    /// conversion specifier by one or more modifier characters.
758    ///
759    /// The following modifiers are supported for many of the numeric
760    /// conversions:
761    ///
762    /// - `O`: Use alternative numeric symbols, if the current locale supports those.
763    /// - `_`: Pad a numeric result with spaces. This overrides the default padding
764    ///   for the specifier.
765    /// - `-`: Do not pad a numeric result. This overrides the default padding
766    ///   for the specifier.
767    /// - `0`: Pad a numeric result with zeros. This overrides the default padding
768    ///   for the specifier.
769    ///
770    /// The following modifiers are supported for many of the alphabetic conversions:
771    ///
772    /// - `^`: Use upper case if possible. This is a gnulib `strftime()` extension.
773    ///   Since: 2.80
774    /// - `#`: Use opposite case if possible. This is a gnulib `strftime()`
775    ///   extension. Since: 2.80
776    ///
777    /// Additionally, when `O` is used with `B`, `b`, or `h`, it produces the alternative
778    /// form of a month name. The alternative form should be used when the month
779    /// name is used without a day number (e.g., standalone). It is required in
780    /// some languages (Baltic, Slavic, Greek, and more) due to their grammatical
781    /// rules. For other languages there is no difference. ``OB`` is a GNU and BSD
782    /// `strftime()` extension expected to be added to the future POSIX specification,
783    /// ``Ob`` and ``Oh`` are GNU `strftime()` extensions. Since: 2.56
784    ///
785    /// Since GLib 2.80, when `E` is used with ``c``, ``C``, ``x``, ``X``, ``y`` or ``Y``,
786    /// the date is formatted using an alternate era representation specific to the
787    /// locale. This is typically used for the Thai solar calendar or Japanese era
788    /// names, for example.
789    ///
790    /// - ``Ec``: the preferred date and time representation for the current locale,
791    ///   using the alternate era representation
792    /// - ``EC``: the name of the era
793    /// - ``Ex``: the preferred date representation for the current locale without
794    ///   the time, using the alternate era representation
795    /// - ``EX``: the preferred time representation for the current locale without
796    ///   the date, using the alternate era representation
797    /// - ``Ey``: the year since the beginning of the era denoted by the ``EC``
798    ///   specifier
799    /// - ``EY``: the full alternative year representation
800    /// ## `format`
801    /// a valid UTF-8 string, containing the format for the
802    ///          #GDateTime
803    ///
804    /// # Returns
805    ///
806    /// a newly allocated string formatted to
807    ///    the requested format or [`None`] in the case that there was an error (such
808    ///    as a format specifier not being supported in the current locale). The
809    ///    string should be freed with g_free().
810    #[doc(alias = "g_date_time_format")]
811    pub fn format(&self, format: &str) -> Result<crate::GString, BoolError> {
812        unsafe {
813            Option::<_>::from_glib_full(ffi::g_date_time_format(
814                self.to_glib_none().0,
815                format.to_glib_none().0,
816            ))
817            .ok_or_else(|| crate::bool_error!("Invalid date"))
818        }
819    }
820
821    /// Format @self in [ISO 8601 format](https://en.wikipedia.org/wiki/ISO_8601),
822    /// including the date, time and time zone, and return that as a UTF-8 encoded
823    /// string.
824    ///
825    /// Since GLib 2.66, this will output to sub-second precision if needed.
826    ///
827    /// # Returns
828    ///
829    /// a newly allocated string formatted in
830    ///   ISO 8601 format or [`None`] in the case that there was an error. The string
831    ///   should be freed with g_free().
832    #[cfg(feature = "v2_62")]
833    #[cfg_attr(docsrs, doc(cfg(feature = "v2_62")))]
834    #[doc(alias = "g_date_time_format_iso8601")]
835    pub fn format_iso8601(&self) -> Result<crate::GString, BoolError> {
836        unsafe {
837            Option::<_>::from_glib_full(ffi::g_date_time_format_iso8601(self.to_glib_none().0))
838                .ok_or_else(|| crate::bool_error!("Invalid date"))
839        }
840    }
841
842    /// Retrieves the day of the month represented by @self in the gregorian
843    /// calendar.
844    ///
845    /// # Returns
846    ///
847    /// the day of the month
848    #[doc(alias = "g_date_time_get_day_of_month")]
849    #[doc(alias = "get_day_of_month")]
850    pub fn day_of_month(&self) -> i32 {
851        unsafe { ffi::g_date_time_get_day_of_month(self.to_glib_none().0) }
852    }
853
854    /// Retrieves the ISO 8601 day of the week on which @self falls (1 is
855    /// Monday, 2 is Tuesday... 7 is Sunday).
856    ///
857    /// # Returns
858    ///
859    /// the day of the week
860    #[doc(alias = "g_date_time_get_day_of_week")]
861    #[doc(alias = "get_day_of_week")]
862    pub fn day_of_week(&self) -> i32 {
863        unsafe { ffi::g_date_time_get_day_of_week(self.to_glib_none().0) }
864    }
865
866    /// Retrieves the day of the year represented by @self in the Gregorian
867    /// calendar.
868    ///
869    /// # Returns
870    ///
871    /// the day of the year
872    #[doc(alias = "g_date_time_get_day_of_year")]
873    #[doc(alias = "get_day_of_year")]
874    pub fn day_of_year(&self) -> i32 {
875        unsafe { ffi::g_date_time_get_day_of_year(self.to_glib_none().0) }
876    }
877
878    /// Retrieves the hour of the day represented by @self
879    ///
880    /// # Returns
881    ///
882    /// the hour of the day
883    #[doc(alias = "g_date_time_get_hour")]
884    #[doc(alias = "get_hour")]
885    pub fn hour(&self) -> i32 {
886        unsafe { ffi::g_date_time_get_hour(self.to_glib_none().0) }
887    }
888
889    /// Retrieves the microsecond of the date represented by @self
890    ///
891    /// # Returns
892    ///
893    /// the microsecond of the second
894    #[doc(alias = "g_date_time_get_microsecond")]
895    #[doc(alias = "get_microsecond")]
896    pub fn microsecond(&self) -> i32 {
897        unsafe { ffi::g_date_time_get_microsecond(self.to_glib_none().0) }
898    }
899
900    /// Retrieves the minute of the hour represented by @self
901    ///
902    /// # Returns
903    ///
904    /// the minute of the hour
905    #[doc(alias = "g_date_time_get_minute")]
906    #[doc(alias = "get_minute")]
907    pub fn minute(&self) -> i32 {
908        unsafe { ffi::g_date_time_get_minute(self.to_glib_none().0) }
909    }
910
911    /// Retrieves the month of the year represented by @self in the Gregorian
912    /// calendar.
913    ///
914    /// # Returns
915    ///
916    /// the month represented by @self
917    #[doc(alias = "g_date_time_get_month")]
918    #[doc(alias = "get_month")]
919    pub fn month(&self) -> i32 {
920        unsafe { ffi::g_date_time_get_month(self.to_glib_none().0) }
921    }
922
923    /// Retrieves the second of the minute represented by @self
924    ///
925    /// # Returns
926    ///
927    /// the second represented by @self
928    #[doc(alias = "g_date_time_get_second")]
929    #[doc(alias = "get_second")]
930    pub fn second(&self) -> i32 {
931        unsafe { ffi::g_date_time_get_second(self.to_glib_none().0) }
932    }
933
934    /// Retrieves the number of seconds since the start of the last minute,
935    /// including the fractional part.
936    ///
937    /// # Returns
938    ///
939    /// the number of seconds
940    #[doc(alias = "g_date_time_get_seconds")]
941    #[doc(alias = "get_seconds")]
942    pub fn seconds(&self) -> f64 {
943        unsafe { ffi::g_date_time_get_seconds(self.to_glib_none().0) }
944    }
945
946    /// Get the time zone for this @self.
947    ///
948    /// # Returns
949    ///
950    /// the time zone
951    #[cfg(feature = "v2_58")]
952    #[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))]
953    #[doc(alias = "g_date_time_get_timezone")]
954    #[doc(alias = "get_timezone")]
955    pub fn timezone(&self) -> TimeZone {
956        unsafe { from_glib_none(ffi::g_date_time_get_timezone(self.to_glib_none().0)) }
957    }
958
959    /// Determines the time zone abbreviation to be used at the time and in
960    /// the time zone of @self.
961    ///
962    /// For example, in Toronto this is currently "EST" during the winter
963    /// months and "EDT" during the summer months when daylight savings
964    /// time is in effect.
965    ///
966    /// # Returns
967    ///
968    /// the time zone abbreviation. The returned
969    ///          string is owned by the #GDateTime and it should not be
970    ///          modified or freed
971    #[doc(alias = "g_date_time_get_timezone_abbreviation")]
972    #[doc(alias = "get_timezone_abbreviation")]
973    pub fn timezone_abbreviation(&self) -> crate::GString {
974        unsafe {
975            from_glib_none(ffi::g_date_time_get_timezone_abbreviation(
976                self.to_glib_none().0,
977            ))
978        }
979    }
980
981    /// Determines the offset to UTC in effect at the time and in the time
982    /// zone of @self.
983    ///
984    /// The offset is the number of microseconds that you add to UTC time to
985    /// arrive at local time for the time zone (ie: negative numbers for time
986    /// zones west of GMT, positive numbers for east).
987    ///
988    /// If @self represents UTC time, then the offset is always zero.
989    ///
990    /// # Returns
991    ///
992    /// the number of microseconds that should be added to UTC to
993    ///          get the local time
994    #[doc(alias = "g_date_time_get_utc_offset")]
995    #[doc(alias = "get_utc_offset")]
996    pub fn utc_offset(&self) -> TimeSpan {
997        unsafe { from_glib(ffi::g_date_time_get_utc_offset(self.to_glib_none().0)) }
998    }
999
1000    /// Returns the ISO 8601 week-numbering year in which the week containing
1001    /// @self falls.
1002    ///
1003    /// This function, taken together with g_date_time_get_week_of_year() and
1004    /// g_date_time_get_day_of_week() can be used to determine the full ISO
1005    /// week date on which @self falls.
1006    ///
1007    /// This is usually equal to the normal Gregorian year (as returned by
1008    /// g_date_time_get_year()), except as detailed below:
1009    ///
1010    /// For Thursday, the week-numbering year is always equal to the usual
1011    /// calendar year.  For other days, the number is such that every day
1012    /// within a complete week (Monday to Sunday) is contained within the
1013    /// same week-numbering year.
1014    ///
1015    /// For Monday, Tuesday and Wednesday occurring near the end of the year,
1016    /// this may mean that the week-numbering year is one greater than the
1017    /// calendar year (so that these days have the same week-numbering year
1018    /// as the Thursday occurring early in the next year).
1019    ///
1020    /// For Friday, Saturday and Sunday occurring near the start of the year,
1021    /// this may mean that the week-numbering year is one less than the
1022    /// calendar year (so that these days have the same week-numbering year
1023    /// as the Thursday occurring late in the previous year).
1024    ///
1025    /// An equivalent description is that the week-numbering year is equal to
1026    /// the calendar year containing the majority of the days in the current
1027    /// week (Monday to Sunday).
1028    ///
1029    /// Note that January 1 0001 in the proleptic Gregorian calendar is a
1030    /// Monday, so this function never returns 0.
1031    ///
1032    /// # Returns
1033    ///
1034    /// the ISO 8601 week-numbering year for @self
1035    #[doc(alias = "g_date_time_get_week_numbering_year")]
1036    #[doc(alias = "get_week_numbering_year")]
1037    pub fn week_numbering_year(&self) -> i32 {
1038        unsafe { ffi::g_date_time_get_week_numbering_year(self.to_glib_none().0) }
1039    }
1040
1041    /// Returns the ISO 8601 week number for the week containing @self.
1042    /// The ISO 8601 week number is the same for every day of the week (from
1043    /// Moday through Sunday).  That can produce some unusual results
1044    /// (described below).
1045    ///
1046    /// The first week of the year is week 1.  This is the week that contains
1047    /// the first Thursday of the year.  Equivalently, this is the first week
1048    /// that has more than 4 of its days falling within the calendar year.
1049    ///
1050    /// The value 0 is never returned by this function.  Days contained
1051    /// within a year but occurring before the first ISO 8601 week of that
1052    /// year are considered as being contained in the last week of the
1053    /// previous year.  Similarly, the final days of a calendar year may be
1054    /// considered as being part of the first ISO 8601 week of the next year
1055    /// if 4 or more days of that week are contained within the new year.
1056    ///
1057    /// # Returns
1058    ///
1059    /// the ISO 8601 week number for @self.
1060    #[doc(alias = "g_date_time_get_week_of_year")]
1061    #[doc(alias = "get_week_of_year")]
1062    pub fn week_of_year(&self) -> i32 {
1063        unsafe { ffi::g_date_time_get_week_of_year(self.to_glib_none().0) }
1064    }
1065
1066    /// Retrieves the year represented by @self in the Gregorian calendar.
1067    ///
1068    /// # Returns
1069    ///
1070    /// the year represented by @self
1071    #[doc(alias = "g_date_time_get_year")]
1072    #[doc(alias = "get_year")]
1073    pub fn year(&self) -> i32 {
1074        unsafe { ffi::g_date_time_get_year(self.to_glib_none().0) }
1075    }
1076
1077    /// Retrieves the Gregorian day, month, and year of a given #GDateTime.
1078    ///
1079    /// # Returns
1080    ///
1081    ///
1082    /// ## `year`
1083    /// the return location for the gregorian year, or [`None`].
1084    ///
1085    /// ## `month`
1086    /// the return location for the month of the year, or [`None`].
1087    ///
1088    /// ## `day`
1089    /// the return location for the day of the month, or [`None`].
1090    #[doc(alias = "g_date_time_get_ymd")]
1091    #[doc(alias = "get_ymd")]
1092    pub fn ymd(&self) -> (i32, i32, i32) {
1093        unsafe {
1094            let mut year = std::mem::MaybeUninit::uninit();
1095            let mut month = std::mem::MaybeUninit::uninit();
1096            let mut day = std::mem::MaybeUninit::uninit();
1097            ffi::g_date_time_get_ymd(
1098                self.to_glib_none().0,
1099                year.as_mut_ptr(),
1100                month.as_mut_ptr(),
1101                day.as_mut_ptr(),
1102            );
1103            (year.assume_init(), month.assume_init(), day.assume_init())
1104        }
1105    }
1106
1107    #[doc(alias = "g_date_time_hash")]
1108    fn hash(&self) -> u32 {
1109        unsafe {
1110            ffi::g_date_time_hash(
1111                ToGlibPtr::<*mut ffi::GDateTime>::to_glib_none(self).0 as ffi::gconstpointer,
1112            )
1113        }
1114    }
1115
1116    /// Determines if daylight savings time is in effect at the time and in
1117    /// the time zone of @self.
1118    ///
1119    /// # Returns
1120    ///
1121    /// [`true`] if daylight savings time is in effect
1122    #[doc(alias = "g_date_time_is_daylight_savings")]
1123    pub fn is_daylight_savings(&self) -> bool {
1124        unsafe { from_glib(ffi::g_date_time_is_daylight_savings(self.to_glib_none().0)) }
1125    }
1126
1127    /// Creates a new #GDateTime corresponding to the same instant in time as
1128    /// @self, but in the local time zone.
1129    ///
1130    /// This call is equivalent to calling g_date_time_to_timezone() with the
1131    /// time zone returned by g_time_zone_new_local().
1132    ///
1133    /// # Returns
1134    ///
1135    /// the newly created #GDateTime which
1136    ///   should be freed with g_date_time_unref(), or [`None`]
1137    #[doc(alias = "g_date_time_to_local")]
1138    pub fn to_local(&self) -> Result<DateTime, BoolError> {
1139        unsafe {
1140            Option::<_>::from_glib_full(ffi::g_date_time_to_local(self.to_glib_none().0))
1141                .ok_or_else(|| crate::bool_error!("Invalid date"))
1142        }
1143    }
1144
1145    //#[cfg_attr(feature = "v2_62", deprecated = "Since 2.62")]
1146    //#[allow(deprecated)]
1147    //#[doc(alias = "g_date_time_to_timeval")]
1148    //pub fn to_timeval(&self, tv: /*Ignored*/&mut TimeVal) -> bool {
1149    //    unsafe { TODO: call ffi:g_date_time_to_timeval() }
1150    //}
1151
1152    /// Create a new #GDateTime corresponding to the same instant in time as
1153    /// @self, but in the time zone @tz.
1154    ///
1155    /// This call can fail in the case that the time goes out of bounds.  For
1156    /// example, converting 0001-01-01 00:00:00 UTC to a time zone west of
1157    /// Greenwich will fail (due to the year 0 being out of range).
1158    /// ## `tz`
1159    /// the new #GTimeZone
1160    ///
1161    /// # Returns
1162    ///
1163    /// the newly created #GDateTime which
1164    ///   should be freed with g_date_time_unref(), or [`None`]
1165    #[doc(alias = "g_date_time_to_timezone")]
1166    pub fn to_timezone(&self, tz: &TimeZone) -> Result<DateTime, BoolError> {
1167        unsafe {
1168            Option::<_>::from_glib_full(ffi::g_date_time_to_timezone(
1169                self.to_glib_none().0,
1170                tz.to_glib_none().0,
1171            ))
1172            .ok_or_else(|| crate::bool_error!("Invalid date"))
1173        }
1174    }
1175
1176    /// Gives the Unix time corresponding to @self, rounding down to the
1177    /// nearest second.
1178    ///
1179    /// Unix time is the number of seconds that have elapsed since 1970-01-01
1180    /// 00:00:00 UTC, regardless of the time zone associated with @self.
1181    ///
1182    /// # Returns
1183    ///
1184    /// the Unix time corresponding to @self
1185    #[doc(alias = "g_date_time_to_unix")]
1186    pub fn to_unix(&self) -> i64 {
1187        unsafe { ffi::g_date_time_to_unix(self.to_glib_none().0) }
1188    }
1189
1190    /// Gives the Unix time corresponding to @self, in microseconds.
1191    ///
1192    /// Unix time is the number of microseconds that have elapsed since 1970-01-01
1193    /// 00:00:00 UTC, regardless of the time zone associated with @self.
1194    ///
1195    /// # Returns
1196    ///
1197    /// the Unix time corresponding to @self
1198    #[cfg(feature = "v2_80")]
1199    #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
1200    #[doc(alias = "g_date_time_to_unix_usec")]
1201    pub fn to_unix_usec(&self) -> i64 {
1202        unsafe { ffi::g_date_time_to_unix_usec(self.to_glib_none().0) }
1203    }
1204
1205    /// Creates a new #GDateTime corresponding to the same instant in time as
1206    /// @self, but in UTC.
1207    ///
1208    /// This call is equivalent to calling g_date_time_to_timezone() with the
1209    /// time zone returned by g_time_zone_new_utc().
1210    ///
1211    /// # Returns
1212    ///
1213    /// the newly created #GDateTime which
1214    ///   should be freed with g_date_time_unref(), or [`None`]
1215    #[doc(alias = "g_date_time_to_utc")]
1216    pub fn to_utc(&self) -> Result<DateTime, BoolError> {
1217        unsafe {
1218            Option::<_>::from_glib_full(ffi::g_date_time_to_utc(self.to_glib_none().0))
1219                .ok_or_else(|| crate::bool_error!("Invalid date"))
1220        }
1221    }
1222}
1223
1224impl PartialOrd for DateTime {
1225    #[inline]
1226    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
1227        Some(self.cmp(other))
1228    }
1229}
1230
1231impl Ord for DateTime {
1232    #[inline]
1233    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
1234        self.compare(other).cmp(&0)
1235    }
1236}
1237
1238impl PartialEq for DateTime {
1239    #[inline]
1240    fn eq(&self, other: &Self) -> bool {
1241        self.equal(other)
1242    }
1243}
1244
1245impl Eq for DateTime {}
1246
1247impl std::hash::Hash for DateTime {
1248    #[inline]
1249    fn hash<H>(&self, state: &mut H)
1250    where
1251        H: std::hash::Hasher,
1252    {
1253        std::hash::Hash::hash(&self.hash(), state)
1254    }
1255}
1256
1257unsafe impl Send for DateTime {}
1258unsafe impl Sync for DateTime {}