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