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::{translate::*, BoolError, TimeSpan, TimeZone};
6use std::{cmp, hash, mem};
7
8crate::wrapper! {
9 #[derive(Debug)]
10 pub struct DateTime(Shared<ffi::GDateTime>);
11
12 match fn {
13 ref => |ptr| ffi::g_date_time_ref(ptr),
14 unref => |ptr| ffi::g_date_time_unref(ptr),
15 type_ => || ffi::g_date_time_get_type(),
16 }
17}
18
19impl DateTime {
20 #[doc(alias = "g_date_time_new")]
21 pub fn new(
22 tz: &TimeZone,
23 year: i32,
24 month: i32,
25 day: i32,
26 hour: i32,
27 minute: i32,
28 seconds: f64,
29 ) -> Result<DateTime, BoolError> {
30 unsafe {
31 Option::<_>::from_glib_full(ffi::g_date_time_new(
32 tz.to_glib_none().0,
33 year,
34 month,
35 day,
36 hour,
37 minute,
38 seconds,
39 ))
40 .ok_or_else(|| crate::bool_error!("Invalid date"))
41 }
42 }
43
44 #[doc(alias = "g_date_time_new_from_iso8601")]
45 #[doc(alias = "new_from_iso8601")]
46 pub fn from_iso8601(text: &str, default_tz: Option<&TimeZone>) -> Result<DateTime, BoolError> {
47 unsafe {
48 Option::<_>::from_glib_full(ffi::g_date_time_new_from_iso8601(
49 text.to_glib_none().0,
50 default_tz.to_glib_none().0,
51 ))
52 .ok_or_else(|| crate::bool_error!("Invalid date"))
53 }
54 }
55
56 //#[cfg_attr(feature = "v2_62", deprecated = "Since 2.62")]
57 //#[allow(deprecated)]
58 //#[doc(alias = "g_date_time_new_from_timeval_local")]
59 //#[doc(alias = "new_from_timeval_local")]
60 //pub fn from_timeval_local(tv: /*Ignored*/&TimeVal) -> Result<DateTime, BoolError> {
61 // unsafe { TODO: call ffi:g_date_time_new_from_timeval_local() }
62 //}
63
64 //#[cfg_attr(feature = "v2_62", deprecated = "Since 2.62")]
65 //#[allow(deprecated)]
66 //#[doc(alias = "g_date_time_new_from_timeval_utc")]
67 //#[doc(alias = "new_from_timeval_utc")]
68 //pub fn from_timeval_utc(tv: /*Ignored*/&TimeVal) -> Result<DateTime, BoolError> {
69 // unsafe { TODO: call ffi:g_date_time_new_from_timeval_utc() }
70 //}
71
72 #[doc(alias = "g_date_time_new_from_unix_local")]
73 #[doc(alias = "new_from_unix_local")]
74 pub fn from_unix_local(t: i64) -> Result<DateTime, BoolError> {
75 unsafe {
76 Option::<_>::from_glib_full(ffi::g_date_time_new_from_unix_local(t))
77 .ok_or_else(|| crate::bool_error!("Invalid date"))
78 }
79 }
80
81 #[doc(alias = "g_date_time_new_from_unix_utc")]
82 #[doc(alias = "new_from_unix_utc")]
83 pub fn from_unix_utc(t: i64) -> Result<DateTime, BoolError> {
84 unsafe {
85 Option::<_>::from_glib_full(ffi::g_date_time_new_from_unix_utc(t))
86 .ok_or_else(|| crate::bool_error!("Invalid date"))
87 }
88 }
89
90 #[doc(alias = "g_date_time_new_local")]
91 #[doc(alias = "new_local")]
92 pub fn from_local(
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_local(
102 year, month, day, hour, minute, seconds,
103 ))
104 .ok_or_else(|| crate::bool_error!("Invalid date"))
105 }
106 }
107
108 #[doc(alias = "g_date_time_new_now")]
109 #[doc(alias = "new_now")]
110 pub fn now(tz: &TimeZone) -> Result<DateTime, BoolError> {
111 unsafe {
112 Option::<_>::from_glib_full(ffi::g_date_time_new_now(tz.to_glib_none().0))
113 .ok_or_else(|| crate::bool_error!("Invalid date"))
114 }
115 }
116
117 #[doc(alias = "g_date_time_new_now_local")]
118 #[doc(alias = "new_now_local")]
119 pub fn now_local() -> Result<DateTime, BoolError> {
120 unsafe {
121 Option::<_>::from_glib_full(ffi::g_date_time_new_now_local())
122 .ok_or_else(|| crate::bool_error!("Invalid date"))
123 }
124 }
125
126 #[doc(alias = "g_date_time_new_now_utc")]
127 #[doc(alias = "new_now_utc")]
128 pub fn now_utc() -> Result<DateTime, BoolError> {
129 unsafe {
130 Option::<_>::from_glib_full(ffi::g_date_time_new_now_utc())
131 .ok_or_else(|| crate::bool_error!("Invalid date"))
132 }
133 }
134
135 #[doc(alias = "g_date_time_new_utc")]
136 #[doc(alias = "new_utc")]
137 pub fn from_utc(
138 year: i32,
139 month: i32,
140 day: i32,
141 hour: i32,
142 minute: i32,
143 seconds: f64,
144 ) -> Result<DateTime, BoolError> {
145 unsafe {
146 Option::<_>::from_glib_full(ffi::g_date_time_new_utc(
147 year, month, day, hour, minute, seconds,
148 ))
149 .ok_or_else(|| crate::bool_error!("Invalid date"))
150 }
151 }
152
153 #[doc(alias = "g_date_time_add")]
154 pub fn add(&self, timespan: TimeSpan) -> Result<DateTime, BoolError> {
155 unsafe {
156 Option::<_>::from_glib_full(ffi::g_date_time_add(
157 self.to_glib_none().0,
158 timespan.into_glib(),
159 ))
160 .ok_or_else(|| crate::bool_error!("Invalid date"))
161 }
162 }
163
164 #[doc(alias = "g_date_time_add_days")]
165 pub fn add_days(&self, days: i32) -> Result<DateTime, BoolError> {
166 unsafe {
167 Option::<_>::from_glib_full(ffi::g_date_time_add_days(self.to_glib_none().0, days))
168 .ok_or_else(|| crate::bool_error!("Invalid date"))
169 }
170 }
171
172 #[doc(alias = "g_date_time_add_full")]
173 pub fn add_full(
174 &self,
175 years: i32,
176 months: i32,
177 days: i32,
178 hours: i32,
179 minutes: i32,
180 seconds: f64,
181 ) -> Result<DateTime, BoolError> {
182 unsafe {
183 Option::<_>::from_glib_full(ffi::g_date_time_add_full(
184 self.to_glib_none().0,
185 years,
186 months,
187 days,
188 hours,
189 minutes,
190 seconds,
191 ))
192 .ok_or_else(|| crate::bool_error!("Invalid date"))
193 }
194 }
195
196 #[doc(alias = "g_date_time_add_hours")]
197 pub fn add_hours(&self, hours: i32) -> Result<DateTime, BoolError> {
198 unsafe {
199 Option::<_>::from_glib_full(ffi::g_date_time_add_hours(self.to_glib_none().0, hours))
200 .ok_or_else(|| crate::bool_error!("Invalid date"))
201 }
202 }
203
204 #[doc(alias = "g_date_time_add_minutes")]
205 pub fn add_minutes(&self, minutes: i32) -> Result<DateTime, BoolError> {
206 unsafe {
207 Option::<_>::from_glib_full(ffi::g_date_time_add_minutes(
208 self.to_glib_none().0,
209 minutes,
210 ))
211 .ok_or_else(|| crate::bool_error!("Invalid date"))
212 }
213 }
214
215 #[doc(alias = "g_date_time_add_months")]
216 pub fn add_months(&self, months: i32) -> Result<DateTime, BoolError> {
217 unsafe {
218 Option::<_>::from_glib_full(ffi::g_date_time_add_months(self.to_glib_none().0, months))
219 .ok_or_else(|| crate::bool_error!("Invalid date"))
220 }
221 }
222
223 #[doc(alias = "g_date_time_add_seconds")]
224 pub fn add_seconds(&self, seconds: f64) -> Result<DateTime, BoolError> {
225 unsafe {
226 Option::<_>::from_glib_full(ffi::g_date_time_add_seconds(
227 self.to_glib_none().0,
228 seconds,
229 ))
230 .ok_or_else(|| crate::bool_error!("Invalid date"))
231 }
232 }
233
234 #[doc(alias = "g_date_time_add_weeks")]
235 pub fn add_weeks(&self, weeks: i32) -> Result<DateTime, BoolError> {
236 unsafe {
237 Option::<_>::from_glib_full(ffi::g_date_time_add_weeks(self.to_glib_none().0, weeks))
238 .ok_or_else(|| crate::bool_error!("Invalid date"))
239 }
240 }
241
242 #[doc(alias = "g_date_time_add_years")]
243 pub fn add_years(&self, years: i32) -> Result<DateTime, BoolError> {
244 unsafe {
245 Option::<_>::from_glib_full(ffi::g_date_time_add_years(self.to_glib_none().0, years))
246 .ok_or_else(|| crate::bool_error!("Invalid date"))
247 }
248 }
249
250 #[doc(alias = "g_date_time_compare")]
251 fn compare(&self, dt2: &DateTime) -> i32 {
252 unsafe {
253 ffi::g_date_time_compare(
254 ToGlibPtr::<*mut ffi::GDateTime>::to_glib_none(self).0 as ffi::gconstpointer,
255 ToGlibPtr::<*mut ffi::GDateTime>::to_glib_none(dt2).0 as ffi::gconstpointer,
256 )
257 }
258 }
259
260 #[doc(alias = "g_date_time_difference")]
261 pub fn difference(&self, begin: &DateTime) -> TimeSpan {
262 unsafe {
263 from_glib(ffi::g_date_time_difference(
264 self.to_glib_none().0,
265 begin.to_glib_none().0,
266 ))
267 }
268 }
269
270 #[doc(alias = "g_date_time_equal")]
271 fn equal(&self, dt2: &DateTime) -> bool {
272 unsafe {
273 from_glib(ffi::g_date_time_equal(
274 ToGlibPtr::<*mut ffi::GDateTime>::to_glib_none(self).0 as ffi::gconstpointer,
275 ToGlibPtr::<*mut ffi::GDateTime>::to_glib_none(dt2).0 as ffi::gconstpointer,
276 ))
277 }
278 }
279
280 #[doc(alias = "g_date_time_format")]
281 pub fn format(&self, format: &str) -> Result<crate::GString, BoolError> {
282 unsafe {
283 Option::<_>::from_glib_full(ffi::g_date_time_format(
284 self.to_glib_none().0,
285 format.to_glib_none().0,
286 ))
287 .ok_or_else(|| crate::bool_error!("Invalid date"))
288 }
289 }
290
291 #[cfg(feature = "v2_62")]
292 #[cfg_attr(docsrs, doc(cfg(feature = "v2_62")))]
293 #[doc(alias = "g_date_time_format_iso8601")]
294 pub fn format_iso8601(&self) -> Result<crate::GString, BoolError> {
295 unsafe {
296 Option::<_>::from_glib_full(ffi::g_date_time_format_iso8601(self.to_glib_none().0))
297 .ok_or_else(|| crate::bool_error!("Invalid date"))
298 }
299 }
300
301 #[doc(alias = "g_date_time_get_day_of_month")]
302 #[doc(alias = "get_day_of_month")]
303 pub fn day_of_month(&self) -> i32 {
304 unsafe { ffi::g_date_time_get_day_of_month(self.to_glib_none().0) }
305 }
306
307 #[doc(alias = "g_date_time_get_day_of_week")]
308 #[doc(alias = "get_day_of_week")]
309 pub fn day_of_week(&self) -> i32 {
310 unsafe { ffi::g_date_time_get_day_of_week(self.to_glib_none().0) }
311 }
312
313 #[doc(alias = "g_date_time_get_day_of_year")]
314 #[doc(alias = "get_day_of_year")]
315 pub fn day_of_year(&self) -> i32 {
316 unsafe { ffi::g_date_time_get_day_of_year(self.to_glib_none().0) }
317 }
318
319 #[doc(alias = "g_date_time_get_hour")]
320 #[doc(alias = "get_hour")]
321 pub fn hour(&self) -> i32 {
322 unsafe { ffi::g_date_time_get_hour(self.to_glib_none().0) }
323 }
324
325 #[doc(alias = "g_date_time_get_microsecond")]
326 #[doc(alias = "get_microsecond")]
327 pub fn microsecond(&self) -> i32 {
328 unsafe { ffi::g_date_time_get_microsecond(self.to_glib_none().0) }
329 }
330
331 #[doc(alias = "g_date_time_get_minute")]
332 #[doc(alias = "get_minute")]
333 pub fn minute(&self) -> i32 {
334 unsafe { ffi::g_date_time_get_minute(self.to_glib_none().0) }
335 }
336
337 #[doc(alias = "g_date_time_get_month")]
338 #[doc(alias = "get_month")]
339 pub fn month(&self) -> i32 {
340 unsafe { ffi::g_date_time_get_month(self.to_glib_none().0) }
341 }
342
343 #[doc(alias = "g_date_time_get_second")]
344 #[doc(alias = "get_second")]
345 pub fn second(&self) -> i32 {
346 unsafe { ffi::g_date_time_get_second(self.to_glib_none().0) }
347 }
348
349 #[doc(alias = "g_date_time_get_seconds")]
350 #[doc(alias = "get_seconds")]
351 pub fn seconds(&self) -> f64 {
352 unsafe { ffi::g_date_time_get_seconds(self.to_glib_none().0) }
353 }
354
355 #[cfg(feature = "v2_58")]
356 #[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))]
357 #[doc(alias = "g_date_time_get_timezone")]
358 #[doc(alias = "get_timezone")]
359 pub fn timezone(&self) -> TimeZone {
360 unsafe { from_glib_none(ffi::g_date_time_get_timezone(self.to_glib_none().0)) }
361 }
362
363 #[doc(alias = "g_date_time_get_timezone_abbreviation")]
364 #[doc(alias = "get_timezone_abbreviation")]
365 pub fn timezone_abbreviation(&self) -> crate::GString {
366 unsafe {
367 from_glib_none(ffi::g_date_time_get_timezone_abbreviation(
368 self.to_glib_none().0,
369 ))
370 }
371 }
372
373 #[doc(alias = "g_date_time_get_utc_offset")]
374 #[doc(alias = "get_utc_offset")]
375 pub fn utc_offset(&self) -> TimeSpan {
376 unsafe { from_glib(ffi::g_date_time_get_utc_offset(self.to_glib_none().0)) }
377 }
378
379 #[doc(alias = "g_date_time_get_week_numbering_year")]
380 #[doc(alias = "get_week_numbering_year")]
381 pub fn week_numbering_year(&self) -> i32 {
382 unsafe { ffi::g_date_time_get_week_numbering_year(self.to_glib_none().0) }
383 }
384
385 #[doc(alias = "g_date_time_get_week_of_year")]
386 #[doc(alias = "get_week_of_year")]
387 pub fn week_of_year(&self) -> i32 {
388 unsafe { ffi::g_date_time_get_week_of_year(self.to_glib_none().0) }
389 }
390
391 #[doc(alias = "g_date_time_get_year")]
392 #[doc(alias = "get_year")]
393 pub fn year(&self) -> i32 {
394 unsafe { ffi::g_date_time_get_year(self.to_glib_none().0) }
395 }
396
397 #[doc(alias = "g_date_time_get_ymd")]
398 #[doc(alias = "get_ymd")]
399 pub fn ymd(&self) -> (i32, i32, i32) {
400 unsafe {
401 let mut year = mem::MaybeUninit::uninit();
402 let mut month = mem::MaybeUninit::uninit();
403 let mut day = mem::MaybeUninit::uninit();
404 ffi::g_date_time_get_ymd(
405 self.to_glib_none().0,
406 year.as_mut_ptr(),
407 month.as_mut_ptr(),
408 day.as_mut_ptr(),
409 );
410 (year.assume_init(), month.assume_init(), day.assume_init())
411 }
412 }
413
414 #[doc(alias = "g_date_time_hash")]
415 fn hash(&self) -> u32 {
416 unsafe {
417 ffi::g_date_time_hash(
418 ToGlibPtr::<*mut ffi::GDateTime>::to_glib_none(self).0 as ffi::gconstpointer,
419 )
420 }
421 }
422
423 #[doc(alias = "g_date_time_is_daylight_savings")]
424 pub fn is_daylight_savings(&self) -> bool {
425 unsafe { from_glib(ffi::g_date_time_is_daylight_savings(self.to_glib_none().0)) }
426 }
427
428 #[doc(alias = "g_date_time_to_local")]
429 pub fn to_local(&self) -> Result<DateTime, BoolError> {
430 unsafe {
431 Option::<_>::from_glib_full(ffi::g_date_time_to_local(self.to_glib_none().0))
432 .ok_or_else(|| crate::bool_error!("Invalid date"))
433 }
434 }
435
436 //#[cfg_attr(feature = "v2_62", deprecated = "Since 2.62")]
437 //#[allow(deprecated)]
438 //#[doc(alias = "g_date_time_to_timeval")]
439 //pub fn to_timeval(&self, tv: /*Ignored*/&mut TimeVal) -> bool {
440 // unsafe { TODO: call ffi:g_date_time_to_timeval() }
441 //}
442
443 #[doc(alias = "g_date_time_to_timezone")]
444 pub fn to_timezone(&self, tz: &TimeZone) -> Result<DateTime, BoolError> {
445 unsafe {
446 Option::<_>::from_glib_full(ffi::g_date_time_to_timezone(
447 self.to_glib_none().0,
448 tz.to_glib_none().0,
449 ))
450 .ok_or_else(|| crate::bool_error!("Invalid date"))
451 }
452 }
453
454 #[doc(alias = "g_date_time_to_unix")]
455 pub fn to_unix(&self) -> i64 {
456 unsafe { ffi::g_date_time_to_unix(self.to_glib_none().0) }
457 }
458
459 #[doc(alias = "g_date_time_to_utc")]
460 pub fn to_utc(&self) -> Result<DateTime, BoolError> {
461 unsafe {
462 Option::<_>::from_glib_full(ffi::g_date_time_to_utc(self.to_glib_none().0))
463 .ok_or_else(|| crate::bool_error!("Invalid date"))
464 }
465 }
466}
467
468impl PartialOrd for DateTime {
469 #[inline]
470 fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
471 Some(self.cmp(other))
472 }
473}
474
475impl Ord for DateTime {
476 #[inline]
477 fn cmp(&self, other: &Self) -> cmp::Ordering {
478 self.compare(dt2:other).cmp(&0)
479 }
480}
481
482impl PartialEq for DateTime {
483 #[inline]
484 fn eq(&self, other: &Self) -> bool {
485 self.equal(dt2:other)
486 }
487}
488
489impl Eq for DateTime {}
490
491impl hash::Hash for DateTime {
492 #[inline]
493 fn hash<H>(&self, state: &mut H)
494 where
495 H: hash::Hasher,
496 {
497 hash::Hash::hash(&self.hash(), state)
498 }
499}
500
501unsafe impl Send for DateTime {}
502unsafe impl Sync for DateTime {}
503