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// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use glib::translate::*;
7
8glib::wrapper! {
9 #[derive()]
10 pub struct DateTime(Shared<ffi::GstDateTime>);
11
12 match fn {
13 ref => |ptr| ffi::gst_date_time_ref(ptr),
14 unref => |ptr| ffi::gst_date_time_unref(ptr),
15 type_ => || ffi::gst_date_time_get_type(),
16 }
17}
18
19impl DateTime {
20 #[doc(alias = "gst_date_time_new_from_g_date_time")]
21 #[doc(alias = "new_from_g_date_time")]
22 pub fn from_g_date_time(dt: glib::DateTime) -> DateTime {
23 assert_initialized_main_thread!();
24 unsafe { from_glib_full(ffi::gst_date_time_new_from_g_date_time(dt.into_glib_ptr())) }
25 }
26
27 #[doc(alias = "gst_date_time_new_from_iso8601_string")]
28 #[doc(alias = "new_from_iso8601_string")]
29 pub fn from_iso8601_string(string: &str) -> Result<DateTime, glib::BoolError> {
30 assert_initialized_main_thread!();
31 unsafe {
32 Option::<_>::from_glib_full(ffi::gst_date_time_new_from_iso8601_string(
33 string.to_glib_none().0,
34 ))
35 .ok_or_else(|| glib::bool_error!("Failed to create DateTime from ISO-8601 string"))
36 }
37 }
38
39 #[doc(alias = "gst_date_time_new_from_unix_epoch_local_time")]
40 #[doc(alias = "new_from_unix_epoch_local_time")]
41 pub fn from_unix_epoch_local_time(secs: i64) -> Result<DateTime, glib::BoolError> {
42 assert_initialized_main_thread!();
43 unsafe {
44 Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_local_time(secs))
45 .ok_or_else(|| glib::bool_error!("Can't create DateTime from UNIX epoch"))
46 }
47 }
48
49 #[cfg(feature = "v1_18")]
50 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
51 #[doc(alias = "gst_date_time_new_from_unix_epoch_local_time_usecs")]
52 #[doc(alias = "new_from_unix_epoch_local_time_usecs")]
53 pub fn from_unix_epoch_local_time_usecs(usecs: i64) -> Result<DateTime, glib::BoolError> {
54 assert_initialized_main_thread!();
55 unsafe {
56 Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_local_time_usecs(
57 usecs,
58 ))
59 .ok_or_else(|| glib::bool_error!("Can't create DateTime from UNIX epoch"))
60 }
61 }
62
63 #[doc(alias = "gst_date_time_new_from_unix_epoch_utc")]
64 #[doc(alias = "new_from_unix_epoch_utc")]
65 pub fn from_unix_epoch_utc(secs: i64) -> Result<DateTime, glib::BoolError> {
66 assert_initialized_main_thread!();
67 unsafe {
68 Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_utc(secs))
69 .ok_or_else(|| glib::bool_error!("Can't create DateTime from UNIX epoch"))
70 }
71 }
72
73 #[cfg(feature = "v1_18")]
74 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
75 #[doc(alias = "gst_date_time_new_from_unix_epoch_utc_usecs")]
76 #[doc(alias = "new_from_unix_epoch_utc_usecs")]
77 pub fn from_unix_epoch_utc_usecs(usecs: i64) -> Result<DateTime, glib::BoolError> {
78 assert_initialized_main_thread!();
79 unsafe {
80 Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_utc_usecs(usecs))
81 .ok_or_else(|| glib::bool_error!("Can't create DateTime from UNIX epoch"))
82 }
83 }
84
85 #[doc(alias = "gst_date_time_new_now_local_time")]
86 pub fn new_now_local_time() -> Option<DateTime> {
87 assert_initialized_main_thread!();
88 unsafe { from_glib_full(ffi::gst_date_time_new_now_local_time()) }
89 }
90
91 #[doc(alias = "gst_date_time_new_now_utc")]
92 pub fn new_now_utc() -> Option<DateTime> {
93 assert_initialized_main_thread!();
94 unsafe { from_glib_full(ffi::gst_date_time_new_now_utc()) }
95 }
96
97 #[doc(alias = "gst_date_time_get_year")]
98 #[doc(alias = "get_year")]
99 pub fn year(&self) -> i32 {
100 unsafe { ffi::gst_date_time_get_year(self.to_glib_none().0) }
101 }
102
103 #[doc(alias = "gst_date_time_has_day")]
104 pub fn has_day(&self) -> bool {
105 unsafe { from_glib(ffi::gst_date_time_has_day(self.to_glib_none().0)) }
106 }
107
108 #[doc(alias = "gst_date_time_has_month")]
109 pub fn has_month(&self) -> bool {
110 unsafe { from_glib(ffi::gst_date_time_has_month(self.to_glib_none().0)) }
111 }
112
113 #[doc(alias = "gst_date_time_has_second")]
114 pub fn has_second(&self) -> bool {
115 unsafe { from_glib(ffi::gst_date_time_has_second(self.to_glib_none().0)) }
116 }
117
118 #[doc(alias = "gst_date_time_has_time")]
119 pub fn has_time(&self) -> bool {
120 unsafe { from_glib(ffi::gst_date_time_has_time(self.to_glib_none().0)) }
121 }
122
123 #[doc(alias = "gst_date_time_has_year")]
124 pub fn has_year(&self) -> bool {
125 unsafe { from_glib(ffi::gst_date_time_has_year(self.to_glib_none().0)) }
126 }
127
128 #[doc(alias = "gst_date_time_to_g_date_time")]
129 pub fn to_g_date_time(&self) -> Result<glib::DateTime, glib::BoolError> {
130 unsafe {
131 Option::<_>::from_glib_full(ffi::gst_date_time_to_g_date_time(self.to_glib_none().0))
132 .ok_or_else(|| glib::bool_error!("Can't create glib::DateTime from DateTime"))
133 }
134 }
135
136 #[doc(alias = "gst_date_time_to_iso8601_string")]
137 pub fn to_iso8601_string(&self) -> Result<glib::GString, glib::BoolError> {
138 unsafe {
139 Option::<_>::from_glib_full(ffi::gst_date_time_to_iso8601_string(self.to_glib_none().0))
140 .ok_or_else(|| glib::bool_error!("Failed to create ISO-8601 string from DateTime"))
141 }
142 }
143}
144
145unsafe impl Send for DateTime {}
146unsafe impl Sync for DateTime {}
147