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