1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use glib::translate::*;

glib::wrapper! {
    /// Struct to store date, time and timezone information altogether.
    /// [`crate::DateTime`] is refcounted and immutable.
    ///
    /// Date information is handled using the proleptic Gregorian calendar.
    ///
    /// Provides basic creation functions and accessor functions to its fields.
    #[derive()]
    pub struct DateTime(Shared<ffi::GstDateTime>);

    match fn {
        ref => |ptr| ffi::gst_date_time_ref(ptr),
        unref => |ptr| ffi::gst_date_time_unref(ptr),
        type_ => || ffi::gst_date_time_get_type(),
    }
}

impl DateTime {
    #[doc(alias = "gst_date_time_new_from_g_date_time")]
    #[doc(alias = "new_from_g_date_time")]
    pub fn from_g_date_time(dt: &glib::DateTime) -> DateTime {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gst_date_time_new_from_g_date_time(dt.to_glib_full())) }
    }

    #[doc(alias = "gst_date_time_new_from_iso8601_string")]
    #[doc(alias = "new_from_iso8601_string")]
    pub fn from_iso8601_string(string: &str) -> Result<DateTime, glib::BoolError> {
        assert_initialized_main_thread!();
        unsafe {
            Option::<_>::from_glib_full(ffi::gst_date_time_new_from_iso8601_string(
                string.to_glib_none().0,
            ))
            .ok_or_else(|| glib::bool_error!("Failed to create DateTime from ISO-8601 string"))
        }
    }

    #[doc(alias = "gst_date_time_new_from_unix_epoch_local_time")]
    #[doc(alias = "new_from_unix_epoch_local_time")]
    pub fn from_unix_epoch_local_time(secs: i64) -> Result<DateTime, glib::BoolError> {
        assert_initialized_main_thread!();
        unsafe {
            Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_local_time(secs))
                .ok_or_else(|| glib::bool_error!("Can't create DateTime from UNIX epoch"))
        }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "gst_date_time_new_from_unix_epoch_local_time_usecs")]
    #[doc(alias = "new_from_unix_epoch_local_time_usecs")]
    pub fn from_unix_epoch_local_time_usecs(usecs: i64) -> Result<DateTime, glib::BoolError> {
        assert_initialized_main_thread!();
        unsafe {
            Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_local_time_usecs(
                usecs,
            ))
            .ok_or_else(|| glib::bool_error!("Can't create DateTime from UNIX epoch"))
        }
    }

    #[doc(alias = "gst_date_time_new_from_unix_epoch_utc")]
    #[doc(alias = "new_from_unix_epoch_utc")]
    pub fn from_unix_epoch_utc(secs: i64) -> Result<DateTime, glib::BoolError> {
        assert_initialized_main_thread!();
        unsafe {
            Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_utc(secs))
                .ok_or_else(|| glib::bool_error!("Can't create DateTime from UNIX epoch"))
        }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "gst_date_time_new_from_unix_epoch_utc_usecs")]
    #[doc(alias = "new_from_unix_epoch_utc_usecs")]
    pub fn from_unix_epoch_utc_usecs(usecs: i64) -> Result<DateTime, glib::BoolError> {
        assert_initialized_main_thread!();
        unsafe {
            Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_utc_usecs(usecs))
                .ok_or_else(|| glib::bool_error!("Can't create DateTime from UNIX epoch"))
        }
    }

    /// Creates a new [`crate::DateTime`] representing the current date and time.
    ///
    /// Free-function: gst_date_time_unref
    ///
    /// # Returns
    ///
    /// the newly created [`crate::DateTime`] which should
    ///  be freed with [`Self::unref()`].
    #[doc(alias = "gst_date_time_new_now_local_time")]
    pub fn new_now_local_time() -> DateTime {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gst_date_time_new_now_local_time()) }
    }

    /// Creates a new [`crate::DateTime`] that represents the current instant at Universal
    /// coordinated time.
    ///
    /// Free-function: gst_date_time_unref
    ///
    /// # Returns
    ///
    /// the newly created [`crate::DateTime`] which should
    ///  be freed with [`Self::unref()`].
    #[doc(alias = "gst_date_time_new_now_utc")]
    pub fn new_now_utc() -> DateTime {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gst_date_time_new_now_utc()) }
    }

    #[doc(alias = "gst_date_time_get_year")]
    #[doc(alias = "get_year")]
    pub fn year(&self) -> i32 {
        unsafe { ffi::gst_date_time_get_year(self.to_glib_none().0) }
    }

    ///
    /// # Returns
    ///
    /// [`true`] if `self`<!-- -->'s day field is set, otherwise [`false`]
    #[doc(alias = "gst_date_time_has_day")]
    pub fn has_day(&self) -> bool {
        unsafe { from_glib(ffi::gst_date_time_has_day(self.to_glib_none().0)) }
    }

    ///
    /// # Returns
    ///
    /// [`true`] if `self`<!-- -->'s month field is set, otherwise [`false`]
    #[doc(alias = "gst_date_time_has_month")]
    pub fn has_month(&self) -> bool {
        unsafe { from_glib(ffi::gst_date_time_has_month(self.to_glib_none().0)) }
    }

    ///
    /// # Returns
    ///
    /// [`true`] if `self`<!-- -->'s second field is set, otherwise [`false`]
    #[doc(alias = "gst_date_time_has_second")]
    pub fn has_second(&self) -> bool {
        unsafe { from_glib(ffi::gst_date_time_has_second(self.to_glib_none().0)) }
    }

    ///
    /// # Returns
    ///
    /// [`true`] if `self`<!-- -->'s hour and minute fields are set,
    ///  otherwise [`false`]
    #[doc(alias = "gst_date_time_has_time")]
    pub fn has_time(&self) -> bool {
        unsafe { from_glib(ffi::gst_date_time_has_time(self.to_glib_none().0)) }
    }

    ///
    /// # Returns
    ///
    /// [`true`] if `self`<!-- -->'s year field is set (which should always
    ///  be the case), otherwise [`false`]
    #[doc(alias = "gst_date_time_has_year")]
    pub fn has_year(&self) -> bool {
        unsafe { from_glib(ffi::gst_date_time_has_year(self.to_glib_none().0)) }
    }

    /// Creates a new [`crate::glib::DateTime`] from a fully defined [`crate::DateTime`] object.
    ///
    /// Free-function: g_date_time_unref
    ///
    /// # Returns
    ///
    /// a newly created [`crate::glib::DateTime`], or
    /// [`None`] on error
    #[doc(alias = "gst_date_time_to_g_date_time")]
    pub fn to_g_date_time(&self) -> Result<glib::DateTime, glib::BoolError> {
        unsafe {
            Option::<_>::from_glib_full(ffi::gst_date_time_to_g_date_time(self.to_glib_none().0))
                .ok_or_else(|| glib::bool_error!("Can't create glib::DateTime from DateTime"))
        }
    }

    /// Create a minimal string compatible with ISO-8601. Possible output formats
    /// are (for example): 2012, 2012-06, 2012-06-23, 2012-06-23T23:30Z,
    /// 2012-06-23T23:30+0100, 2012-06-23T23:30:59Z, 2012-06-23T23:30:59+0100
    ///
    /// # Returns
    ///
    /// a newly allocated string formatted according
    ///  to ISO 8601 and only including the datetime fields that are
    ///  valid, or [`None`] in case there was an error. The string should
    ///  be freed with `g_free()`.
    #[doc(alias = "gst_date_time_to_iso8601_string")]
    pub fn to_iso8601_string(&self) -> Result<glib::GString, glib::BoolError> {
        unsafe {
            Option::<_>::from_glib_full(ffi::gst_date_time_to_iso8601_string(self.to_glib_none().0))
                .ok_or_else(|| glib::bool_error!("Failed to create ISO-8601 string from DateTime"))
        }
    }
}

unsafe impl Send for DateTime {}
unsafe impl Sync for DateTime {}