gstreamer-rs/gstreamer/src/auto/date_time.rs

128 lines
4.6 KiB
Rust
Raw Normal View History

2018-04-23 17:34:22 +00:00
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
2017-07-29 14:11:44 +00:00
// DO NOT EDIT
use glib::translate::*;
2020-11-21 13:46:33 +00:00
glib::glib_wrapper! {
#[derive()]
2020-11-21 13:46:33 +00:00
pub struct DateTime(Shared<ffi::GstDateTime>);
2017-07-29 14:11:44 +00:00
match fn {
2020-11-21 13:46:33 +00:00
ref => |ptr| ffi::gst_date_time_ref(ptr),
unref => |ptr| ffi::gst_date_time_unref(ptr),
get_type => || ffi::gst_date_time_get_type(),
2017-07-29 14:11:44 +00:00
}
}
impl DateTime {
2020-06-11 10:27:43 +00:00
pub fn from_g_date_time(dt: &glib::DateTime) -> Result<DateTime, glib::BoolError> {
assert_initialized_main_thread!();
unsafe {
2020-11-21 13:46:33 +00:00
Option::<_>::from_glib_full(ffi::gst_date_time_new_from_g_date_time(dt.to_glib_full()))
.ok_or_else(|| glib::glib_bool_error!("Can't create DateTime from glib::DateTime"))
}
}
2017-07-29 14:11:44 +00:00
2020-06-11 10:27:43 +00:00
pub fn from_iso8601_string(string: &str) -> Result<DateTime, glib::BoolError> {
2017-07-29 14:11:44 +00:00
assert_initialized_main_thread!();
unsafe {
2020-11-21 13:46:33 +00:00
Option::<_>::from_glib_full(ffi::gst_date_time_new_from_iso8601_string(
string.to_glib_none().0,
))
2020-11-21 13:46:33 +00:00
.ok_or_else(|| glib::glib_bool_error!("Failed to create DateTime from ISO-8601 string"))
2017-07-29 14:11:44 +00:00
}
}
pub fn from_unix_epoch_local_time(secs: i64) -> Result<DateTime, glib::BoolError> {
2017-07-29 14:11:44 +00:00
assert_initialized_main_thread!();
unsafe {
Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_local_time(secs))
.ok_or_else(|| glib::glib_bool_error!("Can't create DateTime from UNIX epoch"))
}
2017-07-29 14:11:44 +00:00
}
2020-11-27 13:37:24 +00:00
#[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
pub fn from_unix_epoch_local_time_usecs(usecs: i64) -> Result<DateTime, glib::BoolError> {
2020-04-30 16:51:41 +00:00
assert_initialized_main_thread!();
unsafe {
Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_local_time_usecs(
2020-04-30 16:51:41 +00:00
usecs,
))
.ok_or_else(|| glib::glib_bool_error!("Can't create DateTime from UNIX epoch"))
2020-04-30 16:51:41 +00:00
}
}
pub fn from_unix_epoch_utc(secs: i64) -> Result<DateTime, glib::BoolError> {
2017-07-29 14:11:44 +00:00
assert_initialized_main_thread!();
unsafe {
Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_utc(secs))
.ok_or_else(|| glib::glib_bool_error!("Can't create DateTime from UNIX epoch"))
}
2017-07-29 14:11:44 +00:00
}
2020-11-27 13:37:24 +00:00
#[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
pub fn from_unix_epoch_utc_usecs(usecs: i64) -> Result<DateTime, glib::BoolError> {
2017-07-29 14:11:44 +00:00
assert_initialized_main_thread!();
unsafe {
Option::<_>::from_glib_full(ffi::gst_date_time_new_from_unix_epoch_utc_usecs(usecs))
.ok_or_else(|| glib::glib_bool_error!("Can't create DateTime from UNIX epoch"))
2017-07-29 14:11:44 +00:00
}
}
pub fn new_now_local_time() -> DateTime {
assert_initialized_main_thread!();
2020-11-21 13:46:33 +00:00
unsafe { from_glib_full(ffi::gst_date_time_new_now_local_time()) }
2017-07-29 14:11:44 +00:00
}
pub fn new_now_utc() -> DateTime {
assert_initialized_main_thread!();
2020-11-21 13:46:33 +00:00
unsafe { from_glib_full(ffi::gst_date_time_new_now_utc()) }
2017-07-29 14:11:44 +00:00
}
pub fn get_year(&self) -> i32 {
2020-11-21 13:46:33 +00:00
unsafe { ffi::gst_date_time_get_year(self.to_glib_none().0) }
2017-07-29 14:11:44 +00:00
}
pub fn has_day(&self) -> bool {
2020-11-21 13:46:33 +00:00
unsafe { from_glib(ffi::gst_date_time_has_day(self.to_glib_none().0)) }
2017-07-29 14:11:44 +00:00
}
pub fn has_month(&self) -> bool {
2020-11-21 13:46:33 +00:00
unsafe { from_glib(ffi::gst_date_time_has_month(self.to_glib_none().0)) }
2017-07-29 14:11:44 +00:00
}
pub fn has_second(&self) -> bool {
2020-11-21 13:46:33 +00:00
unsafe { from_glib(ffi::gst_date_time_has_second(self.to_glib_none().0)) }
2017-07-29 14:11:44 +00:00
}
pub fn has_time(&self) -> bool {
2020-11-21 13:46:33 +00:00
unsafe { from_glib(ffi::gst_date_time_has_time(self.to_glib_none().0)) }
2017-07-29 14:11:44 +00:00
}
pub fn has_year(&self) -> bool {
2020-11-21 13:46:33 +00:00
unsafe { from_glib(ffi::gst_date_time_has_year(self.to_glib_none().0)) }
2017-07-29 14:11:44 +00:00
}
pub fn to_g_date_time(&self) -> Result<glib::DateTime, glib::BoolError> {
unsafe {
2020-11-21 13:46:33 +00:00
Option::<_>::from_glib_full(ffi::gst_date_time_to_g_date_time(self.to_glib_none().0))
.ok_or_else(|| glib::glib_bool_error!("Can't create glib::DateTime from DateTime"))
}
}
2017-07-29 14:11:44 +00:00
2020-11-21 13:46:33 +00:00
pub fn to_iso8601_string(&self) -> Result<glib::GString, glib::BoolError> {
2017-07-29 14:11:44 +00:00
unsafe {
2020-11-21 13:46:33 +00:00
Option::<_>::from_glib_full(ffi::gst_date_time_to_iso8601_string(self.to_glib_none().0))
.ok_or_else(|| {
glib::glib_bool_error!("Failed to create ISO-8601 string from DateTime")
})
2017-07-29 14:11:44 +00:00
}
}
}
unsafe impl Send for DateTime {}
unsafe impl Sync for DateTime {}