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::{ffi, translate::*, BoolError, TimeSpan, TimeZone};
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.  The
643    /// #GTimeSpan that is returned is effectively @self - @begin (ie:
644    /// positive if the first parameter is larger).
645    /// ## `begin`
646    /// a #GDateTime
647    ///
648    /// # Returns
649    ///
650    /// the difference between the two #GDateTime, as a time
651    ///   span expressed in microseconds.
652    #[doc(alias = "g_date_time_difference")]
653    pub fn difference(&self, begin: &DateTime) -> TimeSpan {
654        unsafe {
655            from_glib(ffi::g_date_time_difference(
656                self.to_glib_none().0,
657                begin.to_glib_none().0,
658            ))
659        }
660    }
661
662    #[doc(alias = "g_date_time_equal")]
663    fn equal(&self, dt2: &DateTime) -> bool {
664        unsafe {
665            from_glib(ffi::g_date_time_equal(
666                ToGlibPtr::<*mut ffi::GDateTime>::to_glib_none(self).0 as ffi::gconstpointer,
667                ToGlibPtr::<*mut ffi::GDateTime>::to_glib_none(dt2).0 as ffi::gconstpointer,
668            ))
669        }
670    }
671
672    /// Creates a newly allocated string representing the requested @format.
673    ///
674    /// The format strings understood by this function are a subset of the
675    /// `strftime()` format language as specified by C99.  The ``D``, ``U`` and ``W``
676    /// conversions are not supported, nor is the `E` modifier.  The GNU
677    /// extensions ``k``, ``l``, ``s`` and ``P`` are supported, however, as are the
678    /// `0`, `_` and `-` modifiers. The Python extension ``f`` is also supported.
679    ///
680    /// In contrast to `strftime()`, this function always produces a UTF-8
681    /// string, regardless of the current locale.  Note that the rendering of
682    /// many formats is locale-dependent and may not match the `strftime()`
683    /// output exactly.
684    ///
685    /// The following format specifiers are supported:
686    ///
687    /// - ``a``: the abbreviated weekday name according to the current locale
688    /// - ``A``: the full weekday name according to the current locale
689    /// - ``b``: the abbreviated month name according to the current locale
690    /// - ``B``: the full month name according to the current locale
691    /// - ``c``: the preferred date and time representation for the current locale
692    /// - ``C``: the century number (year/100) as a 2-digit integer (00-99)
693    /// - ``d``: the day of the month as a decimal number (range 01 to 31)
694    /// - ``e``: the day of the month as a decimal number (range 1 to 31);
695    ///   single digits are preceded by a figure space (U+2007)
696    /// - ``F``: equivalent to ``Y`-`m`-`d`` (the ISO 8601 date format)
697    /// - ``g``: the last two digits of the ISO 8601 week-based year as a
698    ///   decimal number (00-99). This works well with ``V`` and ``u``.
699    /// - ``G``: the ISO 8601 week-based year as a decimal number. This works
700    ///   well with ``V`` and ``u``.
701    /// - ``h``: equivalent to ``b``
702    /// - ``H``: the hour as a decimal number using a 24-hour clock (range 00 to 23)
703    /// - ``I``: the hour as a decimal number using a 12-hour clock (range 01 to 12)
704    /// - ``j``: the day of the year as a decimal number (range 001 to 366)
705    /// - ``k``: the hour (24-hour clock) as a decimal number (range 0 to 23);
706    ///   single digits are preceded by a figure space (U+2007)
707    /// - ``l``: the hour (12-hour clock) as a decimal number (range 1 to 12);
708    ///   single digits are preceded by a figure space (U+2007)
709    /// - ``m``: the month as a decimal number (range 01 to 12)
710    /// - ``M``: the minute as a decimal number (range 00 to 59)
711    /// - ``f``: the microsecond as a decimal number (range 000000 to 999999)
712    /// - ``p``: either ‘AM’ or ‘PM’ according to the given time value, or the
713    ///   corresponding  strings for the current locale.  Noon is treated as
714    ///   ‘PM’ and midnight as ‘AM’. Use of this format specifier is discouraged, as
715    ///   many locales have no concept of AM/PM formatting. Use ``c`` or ``X`` instead.
716    /// - ``P``: like ``p`` but lowercase: ‘am’ or ‘pm’ or a corresponding string for
717    ///   the current locale. Use of this format specifier is discouraged, as
718    ///   many locales have no concept of AM/PM formatting. Use ``c`` or ``X`` instead.
719    /// - ``r``: the time in a.m. or p.m. notation. Use of this format specifier is
720    ///   discouraged, as many locales have no concept of AM/PM formatting. Use ``c``
721    ///   or ``X`` instead.
722    /// - ``R``: the time in 24-hour notation (``H`:`M``)
723    /// - ``s``: the number of seconds since the Epoch, that is, since 1970-01-01
724    ///   00:00:00 UTC
725    /// - ``S``: the second as a decimal number (range 00 to 60)
726    /// - ``t``: a tab character
727    /// - ``T``: the time in 24-hour notation with seconds (``H`:`M`:`S``)
728    /// - ``u``: the ISO 8601 standard day of the week as a decimal, range 1 to 7,
729    ///    Monday being 1. This works well with ``G`` and ``V``.
730    /// - ``V``: the ISO 8601 standard week number of the current year as a decimal
731    ///   number, range 01 to 53, where week 1 is the first week that has at
732    ///   least 4 days in the new year. See g_date_time_get_week_of_year().
733    ///   This works well with ``G`` and ``u``.
734    /// - ``w``: the day of the week as a decimal, range 0 to 6, Sunday being 0.
735    ///   This is not the ISO 8601 standard format — use ``u`` instead.
736    /// - ``x``: the preferred date representation for the current locale without
737    ///   the time
738    /// - ``X``: the preferred time representation for the current locale without
739    ///   the date
740    /// - ``y``: the year as a decimal number without the century
741    /// - ``Y``: the year as a decimal number including the century
742    /// - ``z``: the time zone as an offset from UTC (`+hhmm`)
743    /// - `%:z`: the time zone as an offset from UTC (`+hh:mm`).
744    ///   This is a gnulib `strftime()` extension. Since: 2.38
745    /// - `%::z`: the time zone as an offset from UTC (`+hh:mm:ss`). This is a
746    ///   gnulib `strftime()` extension. Since: 2.38
747    /// - `%:::z`: the time zone as an offset from UTC, with `:` to necessary
748    ///   precision (e.g., `-04`, `+05:30`). This is a gnulib `strftime()` extension. Since: 2.38
749    /// - ``Z``: the time zone or name or abbreviation
750    /// - `%%`: a literal `%` character
751    ///
752    /// Some conversion specifications can be modified by preceding the
753    /// conversion specifier by one or more modifier characters.
754    ///
755    /// The following modifiers are supported for many of the numeric
756    /// conversions:
757    ///
758    /// - `O`: Use alternative numeric symbols, if the current locale supports those.
759    /// - `_`: Pad a numeric result with spaces. This overrides the default padding
760    ///   for the specifier.
761    /// - `-`: Do not pad a numeric result. This overrides the default padding
762    ///   for the specifier.
763    /// - `0`: Pad a numeric result with zeros. This overrides the default padding
764    ///   for the specifier.
765    ///
766    /// The following modifiers are supported for many of the alphabetic conversions:
767    ///
768    /// - `^`: Use upper case if possible. This is a gnulib `strftime()` extension.
769    ///   Since: 2.80
770    /// - `#`: Use opposite case if possible. This is a gnulib `strftime()`
771    ///   extension. Since: 2.80
772    ///
773    /// Additionally, when `O` is used with `B`, `b`, or `h`, it produces the alternative
774    /// form of a month name. The alternative form should be used when the month
775    /// name is used without a day number (e.g., standalone). It is required in
776    /// some languages (Baltic, Slavic, Greek, and more) due to their grammatical
777    /// rules. For other languages there is no difference. ``OB`` is a GNU and BSD
778    /// `strftime()` extension expected to be added to the future POSIX specification,
779    /// ``Ob`` and ``Oh`` are GNU `strftime()` extensions. Since: 2.56
780    ///
781    /// Since GLib 2.80, when `E` is used with ``c``, ``C``, ``x``, ``X``, ``y`` or ``Y``,
782    /// the date is formatted using an alternate era representation specific to the
783    /// locale. This is typically used for the Thai solar calendar or Japanese era
784    /// names, for example.
785    ///
786    /// - ``Ec``: the preferred date and time representation for the current locale,
787    ///   using the alternate era representation
788    /// - ``EC``: the name of the era
789    /// - ``Ex``: the preferred date representation for the current locale without
790    ///   the time, using the alternate era representation
791    /// - ``EX``: the preferred time representation for the current locale without
792    ///   the date, using the alternate era representation
793    /// - ``Ey``: the year since the beginning of the era denoted by the ``EC``
794    ///   specifier
795    /// - ``EY``: the full alternative year representation
796    /// ## `format`
797    /// a valid UTF-8 string, containing the format for the
798    ///          #GDateTime
799    ///
800    /// # Returns
801    ///
802    /// a newly allocated string formatted to
803    ///    the requested format or [`None`] in the case that there was an error (such
804    ///    as a format specifier not being supported in the current locale). The
805    ///    string should be freed with g_free().
806    #[doc(alias = "g_date_time_format")]
807    pub fn format(&self, format: &str) -> Result<crate::GString, BoolError> {
808        unsafe {
809            Option::<_>::from_glib_full(ffi::g_date_time_format(
810                self.to_glib_none().0,
811                format.to_glib_none().0,
812            ))
813            .ok_or_else(|| crate::bool_error!("Invalid date"))
814        }
815    }
816
817    /// Format @self in [ISO 8601 format](https://en.wikipedia.org/wiki/ISO_8601),
818    /// including the date, time and time zone, and return that as a UTF-8 encoded
819    /// string.
820    ///
821    /// Since GLib 2.66, this will output to sub-second precision if needed.
822    ///
823    /// # Returns
824    ///
825    /// a newly allocated string formatted in
826    ///   ISO 8601 format or [`None`] in the case that there was an error. The string
827    ///   should be freed with g_free().
828    #[cfg(feature = "v2_62")]
829    #[cfg_attr(docsrs, doc(cfg(feature = "v2_62")))]
830    #[doc(alias = "g_date_time_format_iso8601")]
831    pub fn format_iso8601(&self) -> Result<crate::GString, BoolError> {
832        unsafe {
833            Option::<_>::from_glib_full(ffi::g_date_time_format_iso8601(self.to_glib_none().0))
834                .ok_or_else(|| crate::bool_error!("Invalid date"))
835        }
836    }
837
838    /// Retrieves the day of the month represented by @self in the gregorian
839    /// calendar.
840    ///
841    /// # Returns
842    ///
843    /// the day of the month
844    #[doc(alias = "g_date_time_get_day_of_month")]
845    #[doc(alias = "get_day_of_month")]
846    pub fn day_of_month(&self) -> i32 {
847        unsafe { ffi::g_date_time_get_day_of_month(self.to_glib_none().0) }
848    }
849
850    /// Retrieves the ISO 8601 day of the week on which @self falls (1 is
851    /// Monday, 2 is Tuesday... 7 is Sunday).
852    ///
853    /// # Returns
854    ///
855    /// the day of the week
856    #[doc(alias = "g_date_time_get_day_of_week")]
857    #[doc(alias = "get_day_of_week")]
858    pub fn day_of_week(&self) -> i32 {
859        unsafe { ffi::g_date_time_get_day_of_week(self.to_glib_none().0) }
860    }
861
862    /// Retrieves the day of the year represented by @self in the Gregorian
863    /// calendar.
864    ///
865    /// # Returns
866    ///
867    /// the day of the year
868    #[doc(alias = "g_date_time_get_day_of_year")]
869    #[doc(alias = "get_day_of_year")]
870    pub fn day_of_year(&self) -> i32 {
871        unsafe { ffi::g_date_time_get_day_of_year(self.to_glib_none().0) }
872    }
873
874    /// Retrieves the hour of the day represented by @self
875    ///
876    /// # Returns
877    ///
878    /// the hour of the day
879    #[doc(alias = "g_date_time_get_hour")]
880    #[doc(alias = "get_hour")]
881    pub fn hour(&self) -> i32 {
882        unsafe { ffi::g_date_time_get_hour(self.to_glib_none().0) }
883    }
884
885    /// Retrieves the microsecond of the date represented by @self
886    ///
887    /// # Returns
888    ///
889    /// the microsecond of the second
890    #[doc(alias = "g_date_time_get_microsecond")]
891    #[doc(alias = "get_microsecond")]
892    pub fn microsecond(&self) -> i32 {
893        unsafe { ffi::g_date_time_get_microsecond(self.to_glib_none().0) }
894    }
895
896    /// Retrieves the minute of the hour represented by @self
897    ///
898    /// # Returns
899    ///
900    /// the minute of the hour
901    #[doc(alias = "g_date_time_get_minute")]
902    #[doc(alias = "get_minute")]
903    pub fn minute(&self) -> i32 {
904        unsafe { ffi::g_date_time_get_minute(self.to_glib_none().0) }
905    }
906
907    /// Retrieves the month of the year represented by @self in the Gregorian
908    /// calendar.
909    ///
910    /// # Returns
911    ///
912    /// the month represented by @self
913    #[doc(alias = "g_date_time_get_month")]
914    #[doc(alias = "get_month")]
915    pub fn month(&self) -> i32 {
916        unsafe { ffi::g_date_time_get_month(self.to_glib_none().0) }
917    }
918
919    /// Retrieves the second of the minute represented by @self
920    ///
921    /// # Returns
922    ///
923    /// the second represented by @self
924    #[doc(alias = "g_date_time_get_second")]
925    #[doc(alias = "get_second")]
926    pub fn second(&self) -> i32 {
927        unsafe { ffi::g_date_time_get_second(self.to_glib_none().0) }
928    }
929
930    /// Retrieves the number of seconds since the start of the last minute,
931    /// including the fractional part.
932    ///
933    /// # Returns
934    ///
935    /// the number of seconds
936    #[doc(alias = "g_date_time_get_seconds")]
937    #[doc(alias = "get_seconds")]
938    pub fn seconds(&self) -> f64 {
939        unsafe { ffi::g_date_time_get_seconds(self.to_glib_none().0) }
940    }
941
942    /// Get the time zone for this @self.
943    ///
944    /// # Returns
945    ///
946    /// the time zone
947    #[cfg(feature = "v2_58")]
948    #[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))]
949    #[doc(alias = "g_date_time_get_timezone")]
950    #[doc(alias = "get_timezone")]
951    pub fn timezone(&self) -> TimeZone {
952        unsafe { from_glib_none(ffi::g_date_time_get_timezone(self.to_glib_none().0)) }
953    }
954
955    /// Determines the time zone abbreviation to be used at the time and in
956    /// the time zone of @self.
957    ///
958    /// For example, in Toronto this is currently "EST" during the winter
959    /// months and "EDT" during the summer months when daylight savings
960    /// time is in effect.
961    ///
962    /// # Returns
963    ///
964    /// the time zone abbreviation. The returned
965    ///          string is owned by the #GDateTime and it should not be
966    ///          modified or freed
967    #[doc(alias = "g_date_time_get_timezone_abbreviation")]
968    #[doc(alias = "get_timezone_abbreviation")]
969    pub fn timezone_abbreviation(&self) -> crate::GString {
970        unsafe {
971            from_glib_none(ffi::g_date_time_get_timezone_abbreviation(
972                self.to_glib_none().0,
973            ))
974        }
975    }
976
977    /// Determines the offset to UTC in effect at the time and in the time
978    /// zone of @self.
979    ///
980    /// The offset is the number of microseconds that you add to UTC time to
981    /// arrive at local time for the time zone (ie: negative numbers for time
982    /// zones west of GMT, positive numbers for east).
983    ///
984    /// If @self represents UTC time, then the offset is always zero.
985    ///
986    /// # Returns
987    ///
988    /// the number of microseconds that should be added to UTC to
989    ///          get the local time
990    #[doc(alias = "g_date_time_get_utc_offset")]
991    #[doc(alias = "get_utc_offset")]
992    pub fn utc_offset(&self) -> TimeSpan {
993        unsafe { from_glib(ffi::g_date_time_get_utc_offset(self.to_glib_none().0)) }
994    }
995
996    /// Returns the ISO 8601 week-numbering year in which the week containing
997    /// @self falls.
998    ///
999    /// This function, taken together with g_date_time_get_week_of_year() and
1000    /// g_date_time_get_day_of_week() can be used to determine the full ISO
1001    /// week date on which @self falls.
1002    ///
1003    /// This is usually equal to the normal Gregorian year (as returned by
1004    /// g_date_time_get_year()), except as detailed below:
1005    ///
1006    /// For Thursday, the week-numbering year is always equal to the usual
1007    /// calendar year.  For other days, the number is such that every day
1008    /// within a complete week (Monday to Sunday) is contained within the
1009    /// same week-numbering year.
1010    ///
1011    /// For Monday, Tuesday and Wednesday occurring near the end of the year,
1012    /// this may mean that the week-numbering year is one greater than the
1013    /// calendar year (so that these days have the same week-numbering year
1014    /// as the Thursday occurring early in the next year).
1015    ///
1016    /// For Friday, Saturday and Sunday occurring near the start of the year,
1017    /// this may mean that the week-numbering year is one less than the
1018    /// calendar year (so that these days have the same week-numbering year
1019    /// as the Thursday occurring late in the previous year).
1020    ///
1021    /// An equivalent description is that the week-numbering year is equal to
1022    /// the calendar year containing the majority of the days in the current
1023    /// week (Monday to Sunday).
1024    ///
1025    /// Note that January 1 0001 in the proleptic Gregorian calendar is a
1026    /// Monday, so this function never returns 0.
1027    ///
1028    /// # Returns
1029    ///
1030    /// the ISO 8601 week-numbering year for @self
1031    #[doc(alias = "g_date_time_get_week_numbering_year")]
1032    #[doc(alias = "get_week_numbering_year")]
1033    pub fn week_numbering_year(&self) -> i32 {
1034        unsafe { ffi::g_date_time_get_week_numbering_year(self.to_glib_none().0) }
1035    }
1036
1037    /// Returns the ISO 8601 week number for the week containing @self.
1038    /// The ISO 8601 week number is the same for every day of the week (from
1039    /// Moday through Sunday).  That can produce some unusual results
1040    /// (described below).
1041    ///
1042    /// The first week of the year is week 1.  This is the week that contains
1043    /// the first Thursday of the year.  Equivalently, this is the first week
1044    /// that has more than 4 of its days falling within the calendar year.
1045    ///
1046    /// The value 0 is never returned by this function.  Days contained
1047    /// within a year but occurring before the first ISO 8601 week of that
1048    /// year are considered as being contained in the last week of the
1049    /// previous year.  Similarly, the final days of a calendar year may be
1050    /// considered as being part of the first ISO 8601 week of the next year
1051    /// if 4 or more days of that week are contained within the new year.
1052    ///
1053    /// # Returns
1054    ///
1055    /// the ISO 8601 week number for @self.
1056    #[doc(alias = "g_date_time_get_week_of_year")]
1057    #[doc(alias = "get_week_of_year")]
1058    pub fn week_of_year(&self) -> i32 {
1059        unsafe { ffi::g_date_time_get_week_of_year(self.to_glib_none().0) }
1060    }
1061
1062    /// Retrieves the year represented by @self in the Gregorian calendar.
1063    ///
1064    /// # Returns
1065    ///
1066    /// the year represented by @self
1067    #[doc(alias = "g_date_time_get_year")]
1068    #[doc(alias = "get_year")]
1069    pub fn year(&self) -> i32 {
1070        unsafe { ffi::g_date_time_get_year(self.to_glib_none().0) }
1071    }
1072
1073    /// Retrieves the Gregorian day, month, and year of a given #GDateTime.
1074    ///
1075    /// # Returns
1076    ///
1077    ///
1078    /// ## `year`
1079    /// the return location for the gregorian year, or [`None`].
1080    ///
1081    /// ## `month`
1082    /// the return location for the month of the year, or [`None`].
1083    ///
1084    /// ## `day`
1085    /// the return location for the day of the month, or [`None`].
1086    #[doc(alias = "g_date_time_get_ymd")]
1087    #[doc(alias = "get_ymd")]
1088    pub fn ymd(&self) -> (i32, i32, i32) {
1089        unsafe {
1090            let mut year = std::mem::MaybeUninit::uninit();
1091            let mut month = std::mem::MaybeUninit::uninit();
1092            let mut day = std::mem::MaybeUninit::uninit();
1093            ffi::g_date_time_get_ymd(
1094                self.to_glib_none().0,
1095                year.as_mut_ptr(),
1096                month.as_mut_ptr(),
1097                day.as_mut_ptr(),
1098            );
1099            (year.assume_init(), month.assume_init(), day.assume_init())
1100        }
1101    }
1102
1103    #[doc(alias = "g_date_time_hash")]
1104    fn hash(&self) -> u32 {
1105        unsafe {
1106            ffi::g_date_time_hash(
1107                ToGlibPtr::<*mut ffi::GDateTime>::to_glib_none(self).0 as ffi::gconstpointer,
1108            )
1109        }
1110    }
1111
1112    /// Determines if daylight savings time is in effect at the time and in
1113    /// the time zone of @self.
1114    ///
1115    /// # Returns
1116    ///
1117    /// [`true`] if daylight savings time is in effect
1118    #[doc(alias = "g_date_time_is_daylight_savings")]
1119    pub fn is_daylight_savings(&self) -> bool {
1120        unsafe { from_glib(ffi::g_date_time_is_daylight_savings(self.to_glib_none().0)) }
1121    }
1122
1123    /// Creates a new #GDateTime corresponding to the same instant in time as
1124    /// @self, but in the local time zone.
1125    ///
1126    /// This call is equivalent to calling g_date_time_to_timezone() with the
1127    /// time zone returned by g_time_zone_new_local().
1128    ///
1129    /// # Returns
1130    ///
1131    /// the newly created #GDateTime which
1132    ///   should be freed with g_date_time_unref(), or [`None`]
1133    #[doc(alias = "g_date_time_to_local")]
1134    pub fn to_local(&self) -> Result<DateTime, BoolError> {
1135        unsafe {
1136            Option::<_>::from_glib_full(ffi::g_date_time_to_local(self.to_glib_none().0))
1137                .ok_or_else(|| crate::bool_error!("Invalid date"))
1138        }
1139    }
1140
1141    //#[cfg_attr(feature = "v2_62", deprecated = "Since 2.62")]
1142    //#[allow(deprecated)]
1143    //#[doc(alias = "g_date_time_to_timeval")]
1144    //pub fn to_timeval(&self, tv: /*Ignored*/&mut TimeVal) -> bool {
1145    //    unsafe { TODO: call ffi:g_date_time_to_timeval() }
1146    //}
1147
1148    /// Create a new #GDateTime corresponding to the same instant in time as
1149    /// @self, but in the time zone @tz.
1150    ///
1151    /// This call can fail in the case that the time goes out of bounds.  For
1152    /// example, converting 0001-01-01 00:00:00 UTC to a time zone west of
1153    /// Greenwich will fail (due to the year 0 being out of range).
1154    /// ## `tz`
1155    /// the new #GTimeZone
1156    ///
1157    /// # Returns
1158    ///
1159    /// the newly created #GDateTime which
1160    ///   should be freed with g_date_time_unref(), or [`None`]
1161    #[doc(alias = "g_date_time_to_timezone")]
1162    pub fn to_timezone(&self, tz: &TimeZone) -> Result<DateTime, BoolError> {
1163        unsafe {
1164            Option::<_>::from_glib_full(ffi::g_date_time_to_timezone(
1165                self.to_glib_none().0,
1166                tz.to_glib_none().0,
1167            ))
1168            .ok_or_else(|| crate::bool_error!("Invalid date"))
1169        }
1170    }
1171
1172    /// Gives the Unix time corresponding to @self, rounding down to the
1173    /// nearest second.
1174    ///
1175    /// Unix time is the number of seconds that have elapsed since 1970-01-01
1176    /// 00:00:00 UTC, regardless of the time zone associated with @self.
1177    ///
1178    /// # Returns
1179    ///
1180    /// the Unix time corresponding to @self
1181    #[doc(alias = "g_date_time_to_unix")]
1182    pub fn to_unix(&self) -> i64 {
1183        unsafe { ffi::g_date_time_to_unix(self.to_glib_none().0) }
1184    }
1185
1186    /// Gives the Unix time corresponding to @self, in microseconds.
1187    ///
1188    /// Unix time is the number of microseconds that have elapsed since 1970-01-01
1189    /// 00:00:00 UTC, regardless of the time zone associated with @self.
1190    ///
1191    /// # Returns
1192    ///
1193    /// the Unix time corresponding to @self
1194    #[cfg(feature = "v2_80")]
1195    #[cfg_attr(docsrs, doc(cfg(feature = "v2_80")))]
1196    #[doc(alias = "g_date_time_to_unix_usec")]
1197    pub fn to_unix_usec(&self) -> i64 {
1198        unsafe { ffi::g_date_time_to_unix_usec(self.to_glib_none().0) }
1199    }
1200
1201    /// Creates a new #GDateTime corresponding to the same instant in time as
1202    /// @self, but in UTC.
1203    ///
1204    /// This call is equivalent to calling g_date_time_to_timezone() with the
1205    /// time zone returned by g_time_zone_new_utc().
1206    ///
1207    /// # Returns
1208    ///
1209    /// the newly created #GDateTime which
1210    ///   should be freed with g_date_time_unref(), or [`None`]
1211    #[doc(alias = "g_date_time_to_utc")]
1212    pub fn to_utc(&self) -> Result<DateTime, BoolError> {
1213        unsafe {
1214            Option::<_>::from_glib_full(ffi::g_date_time_to_utc(self.to_glib_none().0))
1215                .ok_or_else(|| crate::bool_error!("Invalid date"))
1216        }
1217    }
1218}
1219
1220impl PartialOrd for DateTime {
1221    #[inline]
1222    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
1223        Some(self.cmp(other))
1224    }
1225}
1226
1227impl Ord for DateTime {
1228    #[inline]
1229    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
1230        self.compare(other).cmp(&0)
1231    }
1232}
1233
1234impl PartialEq for DateTime {
1235    #[inline]
1236    fn eq(&self, other: &Self) -> bool {
1237        self.equal(other)
1238    }
1239}
1240
1241impl Eq for DateTime {}
1242
1243impl std::hash::Hash for DateTime {
1244    #[inline]
1245    fn hash<H>(&self, state: &mut H)
1246    where
1247        H: std::hash::Hasher,
1248    {
1249        std::hash::Hash::hash(&self.hash(), state)
1250    }
1251}
1252
1253unsafe impl Send for DateTime {}
1254unsafe impl Sync for DateTime {}