gstreamer/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// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::ffi;
7use glib::translate::*;
8
9glib::wrapper! {
10 /// Struct to store date, time and timezone information altogether.
11 /// [`DateTime`][crate::DateTime] is refcounted and immutable.
12 ///
13 /// Date information is handled using the [proleptic Gregorian calendar].
14 ///
15 /// Provides basic creation functions and accessor functions to its fields.
16 ///
17 /// [proleptic Gregorian calendar]: https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar
18 #[derive()]
19 pub struct DateTime(Shared<ffi::GstDateTime>);
20
21 match fn {
22 ref => |ptr| ffi::gst_date_time_ref(ptr),
23 unref => |ptr| ffi::gst_date_time_unref(ptr),
24 type_ => || ffi::gst_date_time_get_type(),
25 }
26}
27
28impl DateTime {
29 /// Creates a new [`DateTime`][crate::DateTime] from a [`glib::DateTime`][crate::glib::DateTime] object.
30 /// ## `dt`
31 /// the [`glib::DateTime`][crate::glib::DateTime].
32 ///
33 /// # Returns
34 ///
35 /// a newly created [`DateTime`][crate::DateTime],
36 /// or [`None`] if `dt` is [`None`].
37 #[doc(alias = "gst_date_time_new_from_g_date_time")]
38 #[doc(alias = "new_from_g_date_time")]
39 pub fn from_g_date_time(dt: glib::DateTime) -> DateTime {
40 assert_initialized_main_thread!();
41 unsafe { from_glib_full(ffi::gst_date_time_new_from_g_date_time(dt.into_glib_ptr())) }
42 }
43
44 /// Tries to parse common variants of ISO-8601 datetime strings into a
45 /// [`DateTime`][crate::DateTime]. Possible input formats are (for example):
46 /// `2012-06-30T22:46:43Z`, `2012`, `2012-06`, `2012-06-30`, `2012-06-30T22:46:43-0430`,
47 /// `2012-06-30T22:46Z`, `2012-06-30T22:46-0430`, `2012-06-30 22:46`,
48 /// `2012-06-30 22:46:43`, `2012-06-00`, `2012-00-00`, `2012-00-30`, `22:46:43Z`, `22:46Z`,
49 /// `22:46:43-0430`, `22:46-0430`, `22:46:30`, `22:46`
50 /// If no date is provided, it is assumed to be "today" in the timezone
51 /// provided (if any), otherwise UTC.
52 /// ## `string`
53 /// ISO 8601-formatted datetime string.
54 ///
55 /// # Returns
56 ///
57 /// a newly created [`DateTime`][crate::DateTime],
58 /// or [`None`] on error
59 #[doc(alias = "gst_date_time_new_from_iso8601_string")]
60 #[doc(alias = "new_from_iso8601_string")]
61 pub fn from_iso8601_string(string: &str) -> Result<DateTime, glib::BoolError> {
62 assert_initialized_main_thread!();
63 unsafe {
64 Option::<_>::from_glib_full(ffi::gst_date_time_new_from_iso8601_string(
65 string.to_glib_none().0,
66 ))
67 .ok_or_else(|| glib::bool_error!("Failed to create DateTime from ISO-8601 string"))
68 }
69 }
70
71 /// Creates a new [`DateTime`][crate::DateTime] using the time since Jan 1, 1970 specified by
72 /// `secs`. The [`DateTime`][crate::DateTime] is in the local timezone.
73 /// ## `secs`
74 /// seconds from the Unix epoch
75 ///
76 /// # Returns
77 ///
78 /// the newly created [`DateTime`][crate::DateTime],
79 /// or [`None`] on error.
80 #[doc(alias = "gst_date_time_new_from_unix_epoch_local_time")]
81 #[doc(alias = "new_from_unix_epoch_local_time")]
82 pub fn from_unix_epoch_local_time(secs: i64) -> Result<DateTime, glib::BoolError> {
83 assert_initialized_main_thread!();
84 unsafe {
85 Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_local_time(secs))
86 .ok_or_else(|| glib::bool_error!("Can't create DateTime from UNIX epoch"))
87 }
88 }
89
90 /// Creates a new [`DateTime`][crate::DateTime] using the time since Jan 1, 1970 specified by
91 /// `usecs`. The [`DateTime`][crate::DateTime] is in the local timezone.
92 /// ## `usecs`
93 /// microseconds from the Unix epoch
94 ///
95 /// # Returns
96 ///
97 /// a newly created [`DateTime`][crate::DateTime], or [`None`]
98 /// on error.
99 #[cfg(feature = "v1_18")]
100 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
101 #[doc(alias = "gst_date_time_new_from_unix_epoch_local_time_usecs")]
102 #[doc(alias = "new_from_unix_epoch_local_time_usecs")]
103 pub fn from_unix_epoch_local_time_usecs(usecs: i64) -> Result<DateTime, glib::BoolError> {
104 assert_initialized_main_thread!();
105 unsafe {
106 Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_local_time_usecs(
107 usecs,
108 ))
109 .ok_or_else(|| glib::bool_error!("Can't create DateTime from UNIX epoch"))
110 }
111 }
112
113 /// Creates a new [`DateTime`][crate::DateTime] using the time since Jan 1, 1970 specified by
114 /// `secs`. The [`DateTime`][crate::DateTime] is in the UTC timezone.
115 /// ## `secs`
116 /// seconds from the Unix epoch
117 ///
118 /// # Returns
119 ///
120 /// the newly created [`DateTime`][crate::DateTime],
121 /// or [`None`] on error.
122 #[doc(alias = "gst_date_time_new_from_unix_epoch_utc")]
123 #[doc(alias = "new_from_unix_epoch_utc")]
124 pub fn from_unix_epoch_utc(secs: i64) -> Result<DateTime, glib::BoolError> {
125 assert_initialized_main_thread!();
126 unsafe {
127 Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_utc(secs))
128 .ok_or_else(|| glib::bool_error!("Can't create DateTime from UNIX epoch"))
129 }
130 }
131
132 /// Creates a new [`DateTime`][crate::DateTime] using the time since Jan 1, 1970 specified by
133 /// `usecs`. The [`DateTime`][crate::DateTime] is in UTC.
134 /// ## `usecs`
135 /// microseconds from the Unix epoch
136 ///
137 /// # Returns
138 ///
139 /// a newly created [`DateTime`][crate::DateTime], or [`None`]
140 /// on error.
141 #[cfg(feature = "v1_18")]
142 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
143 #[doc(alias = "gst_date_time_new_from_unix_epoch_utc_usecs")]
144 #[doc(alias = "new_from_unix_epoch_utc_usecs")]
145 pub fn from_unix_epoch_utc_usecs(usecs: i64) -> Result<DateTime, glib::BoolError> {
146 assert_initialized_main_thread!();
147 unsafe {
148 Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_utc_usecs(usecs))
149 .ok_or_else(|| glib::bool_error!("Can't create DateTime from UNIX epoch"))
150 }
151 }
152
153 /// Creates a new [`DateTime`][crate::DateTime] representing the current date and time.
154 ///
155 /// # Returns
156 ///
157 /// the newly created [`DateTime`][crate::DateTime] which should
158 /// be freed with `gst_date_time_unref()`, or [`None`] on error.
159 #[doc(alias = "gst_date_time_new_now_local_time")]
160 pub fn new_now_local_time() -> Option<DateTime> {
161 assert_initialized_main_thread!();
162 unsafe { from_glib_full(ffi::gst_date_time_new_now_local_time()) }
163 }
164
165 /// Creates a new [`DateTime`][crate::DateTime] that represents the current instant at Universal
166 /// coordinated time.
167 ///
168 /// # Returns
169 ///
170 /// the newly created [`DateTime`][crate::DateTime] which should
171 /// be freed with `gst_date_time_unref()`, or [`None`] on error.
172 #[doc(alias = "gst_date_time_new_now_utc")]
173 pub fn new_now_utc() -> Option<DateTime> {
174 assert_initialized_main_thread!();
175 unsafe { from_glib_full(ffi::gst_date_time_new_now_utc()) }
176 }
177
178 /// Returns the year of this [`DateTime`][crate::DateTime].
179 /// Call [`has_year()`][Self::has_year()] before, to avoid warnings.
180 ///
181 /// # Returns
182 ///
183 /// The year of this [`DateTime`][crate::DateTime]
184 #[doc(alias = "gst_date_time_get_year")]
185 #[doc(alias = "get_year")]
186 pub fn year(&self) -> i32 {
187 unsafe { ffi::gst_date_time_get_year(self.to_glib_none().0) }
188 }
189
190 ///
191 /// # Returns
192 ///
193 /// [`true`] if `self`<!-- -->'s day field is set, otherwise [`false`]
194 #[doc(alias = "gst_date_time_has_day")]
195 pub fn has_day(&self) -> bool {
196 unsafe { from_glib(ffi::gst_date_time_has_day(self.to_glib_none().0)) }
197 }
198
199 ///
200 /// # Returns
201 ///
202 /// [`true`] if `self`<!-- -->'s month field is set, otherwise [`false`]
203 #[doc(alias = "gst_date_time_has_month")]
204 pub fn has_month(&self) -> bool {
205 unsafe { from_glib(ffi::gst_date_time_has_month(self.to_glib_none().0)) }
206 }
207
208 ///
209 /// # Returns
210 ///
211 /// [`true`] if `self`<!-- -->'s second field is set, otherwise [`false`]
212 #[doc(alias = "gst_date_time_has_second")]
213 pub fn has_second(&self) -> bool {
214 unsafe { from_glib(ffi::gst_date_time_has_second(self.to_glib_none().0)) }
215 }
216
217 ///
218 /// # Returns
219 ///
220 /// [`true`] if `self`<!-- -->'s hour and minute fields are set,
221 /// otherwise [`false`]
222 #[doc(alias = "gst_date_time_has_time")]
223 pub fn has_time(&self) -> bool {
224 unsafe { from_glib(ffi::gst_date_time_has_time(self.to_glib_none().0)) }
225 }
226
227 ///
228 /// # Returns
229 ///
230 /// [`true`] if `self`<!-- -->'s year field is set (which should always
231 /// be the case), otherwise [`false`]
232 #[doc(alias = "gst_date_time_has_year")]
233 pub fn has_year(&self) -> bool {
234 unsafe { from_glib(ffi::gst_date_time_has_year(self.to_glib_none().0)) }
235 }
236
237 /// Creates a new [`glib::DateTime`][crate::glib::DateTime] from a fully defined [`DateTime`][crate::DateTime] object.
238 ///
239 /// # Returns
240 ///
241 /// a newly created [`glib::DateTime`][crate::glib::DateTime], or
242 /// [`None`] on error or if `self` does not have a year, month, day, hour,
243 /// minute and second.
244 #[doc(alias = "gst_date_time_to_g_date_time")]
245 pub fn to_g_date_time(&self) -> Result<glib::DateTime, glib::BoolError> {
246 unsafe {
247 Option::<_>::from_glib_full(ffi::gst_date_time_to_g_date_time(self.to_glib_none().0))
248 .ok_or_else(|| glib::bool_error!("Can't create glib::DateTime from DateTime"))
249 }
250 }
251
252 /// Create a minimal string compatible with ISO-8601. Possible output formats
253 /// are (for example): `2012`, `2012-06`, `2012-06-23`, `2012-06-23T23:30Z`,
254 /// `2012-06-23T23:30+0100`, `2012-06-23T23:30:59Z`, `2012-06-23T23:30:59+0100`
255 ///
256 /// # Returns
257 ///
258 /// a newly allocated string formatted according
259 /// to ISO 8601 and only including the datetime fields that are
260 /// valid, or [`None`] in case there was an error.
261 #[doc(alias = "gst_date_time_to_iso8601_string")]
262 pub fn to_iso8601_string(&self) -> Result<glib::GString, glib::BoolError> {
263 unsafe {
264 Option::<_>::from_glib_full(ffi::gst_date_time_to_iso8601_string(self.to_glib_none().0))
265 .ok_or_else(|| glib::bool_error!("Failed to create ISO-8601 string from DateTime"))
266 }
267 }
268}
269
270unsafe impl Send for DateTime {}
271unsafe impl Sync for DateTime {}