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 // DO NOT EDIT 4 5 use glib_sys; 6 use std::cmp; 7 use std::hash; 8 use std::mem; 9 use translate::*; 10 use GString; 11 use TimeSpan; 12 use TimeZone; 13 14 glib_wrapper! { 15 #[derive(Debug)] 16 pub struct DateTime(Shared<glib_sys::GDateTime>); 17 18 match fn { 19 ref => |ptr| glib_sys::g_date_time_ref(ptr), 20 unref => |ptr| glib_sys::g_date_time_unref(ptr), 21 get_type => || glib_sys::g_date_time_get_type(), 22 } 23 } 24 25 impl DateTime { new( tz: &TimeZone, year: i32, month: i32, day: i32, hour: i32, minute: i32, seconds: f64, ) -> DateTime26 pub fn new( 27 tz: &TimeZone, 28 year: i32, 29 month: i32, 30 day: i32, 31 hour: i32, 32 minute: i32, 33 seconds: f64, 34 ) -> DateTime { 35 unsafe { 36 from_glib_full(glib_sys::g_date_time_new( 37 tz.to_glib_none().0, 38 year, 39 month, 40 day, 41 hour, 42 minute, 43 seconds, 44 )) 45 } 46 } 47 48 #[cfg(any(feature = "v2_56", feature = "dox"))] new_from_iso8601(text: &str, default_tz: Option<&TimeZone>) -> Option<DateTime>49 pub fn new_from_iso8601(text: &str, default_tz: Option<&TimeZone>) -> Option<DateTime> { 50 unsafe { 51 from_glib_full(glib_sys::g_date_time_new_from_iso8601( 52 text.to_glib_none().0, 53 default_tz.to_glib_none().0, 54 )) 55 } 56 } 57 58 //pub fn new_from_timeval_local(tv: /*Ignored*/&TimeVal) -> DateTime { 59 // unsafe { TODO: call glib_sys:g_date_time_new_from_timeval_local() } 60 //} 61 62 //pub fn new_from_timeval_utc(tv: /*Ignored*/&TimeVal) -> DateTime { 63 // unsafe { TODO: call glib_sys:g_date_time_new_from_timeval_utc() } 64 //} 65 new_from_unix_local(t: i64) -> DateTime66 pub fn new_from_unix_local(t: i64) -> DateTime { 67 unsafe { from_glib_full(glib_sys::g_date_time_new_from_unix_local(t)) } 68 } 69 new_from_unix_utc(t: i64) -> DateTime70 pub fn new_from_unix_utc(t: i64) -> DateTime { 71 unsafe { from_glib_full(glib_sys::g_date_time_new_from_unix_utc(t)) } 72 } 73 new_local( year: i32, month: i32, day: i32, hour: i32, minute: i32, seconds: f64, ) -> DateTime74 pub fn new_local( 75 year: i32, 76 month: i32, 77 day: i32, 78 hour: i32, 79 minute: i32, 80 seconds: f64, 81 ) -> DateTime { 82 unsafe { 83 from_glib_full(glib_sys::g_date_time_new_local( 84 year, month, day, hour, minute, seconds, 85 )) 86 } 87 } 88 new_now(tz: &TimeZone) -> DateTime89 pub fn new_now(tz: &TimeZone) -> DateTime { 90 unsafe { from_glib_full(glib_sys::g_date_time_new_now(tz.to_glib_none().0)) } 91 } 92 new_now_local() -> DateTime93 pub fn new_now_local() -> DateTime { 94 unsafe { from_glib_full(glib_sys::g_date_time_new_now_local()) } 95 } 96 new_now_utc() -> DateTime97 pub fn new_now_utc() -> DateTime { 98 unsafe { from_glib_full(glib_sys::g_date_time_new_now_utc()) } 99 } 100 new_utc( year: i32, month: i32, day: i32, hour: i32, minute: i32, seconds: f64, ) -> DateTime101 pub fn new_utc( 102 year: i32, 103 month: i32, 104 day: i32, 105 hour: i32, 106 minute: i32, 107 seconds: f64, 108 ) -> DateTime { 109 unsafe { 110 from_glib_full(glib_sys::g_date_time_new_utc( 111 year, month, day, hour, minute, seconds, 112 )) 113 } 114 } 115 add(&self, timespan: TimeSpan) -> Option<DateTime>116 pub fn add(&self, timespan: TimeSpan) -> Option<DateTime> { 117 unsafe { from_glib_full(glib_sys::g_date_time_add(self.to_glib_none().0, timespan)) } 118 } 119 add_days(&self, days: i32) -> Option<DateTime>120 pub fn add_days(&self, days: i32) -> Option<DateTime> { 121 unsafe { from_glib_full(glib_sys::g_date_time_add_days(self.to_glib_none().0, days)) } 122 } 123 add_full( &self, years: i32, months: i32, days: i32, hours: i32, minutes: i32, seconds: f64, ) -> Option<DateTime>124 pub fn add_full( 125 &self, 126 years: i32, 127 months: i32, 128 days: i32, 129 hours: i32, 130 minutes: i32, 131 seconds: f64, 132 ) -> Option<DateTime> { 133 unsafe { 134 from_glib_full(glib_sys::g_date_time_add_full( 135 self.to_glib_none().0, 136 years, 137 months, 138 days, 139 hours, 140 minutes, 141 seconds, 142 )) 143 } 144 } 145 add_hours(&self, hours: i32) -> Option<DateTime>146 pub fn add_hours(&self, hours: i32) -> Option<DateTime> { 147 unsafe { 148 from_glib_full(glib_sys::g_date_time_add_hours( 149 self.to_glib_none().0, 150 hours, 151 )) 152 } 153 } 154 add_minutes(&self, minutes: i32) -> Option<DateTime>155 pub fn add_minutes(&self, minutes: i32) -> Option<DateTime> { 156 unsafe { 157 from_glib_full(glib_sys::g_date_time_add_minutes( 158 self.to_glib_none().0, 159 minutes, 160 )) 161 } 162 } 163 add_months(&self, months: i32) -> Option<DateTime>164 pub fn add_months(&self, months: i32) -> Option<DateTime> { 165 unsafe { 166 from_glib_full(glib_sys::g_date_time_add_months( 167 self.to_glib_none().0, 168 months, 169 )) 170 } 171 } 172 add_seconds(&self, seconds: f64) -> Option<DateTime>173 pub fn add_seconds(&self, seconds: f64) -> Option<DateTime> { 174 unsafe { 175 from_glib_full(glib_sys::g_date_time_add_seconds( 176 self.to_glib_none().0, 177 seconds, 178 )) 179 } 180 } 181 add_weeks(&self, weeks: i32) -> Option<DateTime>182 pub fn add_weeks(&self, weeks: i32) -> Option<DateTime> { 183 unsafe { 184 from_glib_full(glib_sys::g_date_time_add_weeks( 185 self.to_glib_none().0, 186 weeks, 187 )) 188 } 189 } 190 add_years(&self, years: i32) -> Option<DateTime>191 pub fn add_years(&self, years: i32) -> Option<DateTime> { 192 unsafe { 193 from_glib_full(glib_sys::g_date_time_add_years( 194 self.to_glib_none().0, 195 years, 196 )) 197 } 198 } 199 difference(&self, begin: &DateTime) -> TimeSpan200 pub fn difference(&self, begin: &DateTime) -> TimeSpan { 201 unsafe { glib_sys::g_date_time_difference(self.to_glib_none().0, begin.to_glib_none().0) } 202 } 203 format(&self, format: &str) -> Option<GString>204 pub fn format(&self, format: &str) -> Option<GString> { 205 unsafe { 206 from_glib_full(glib_sys::g_date_time_format( 207 self.to_glib_none().0, 208 format.to_glib_none().0, 209 )) 210 } 211 } 212 get_day_of_month(&self) -> i32213 pub fn get_day_of_month(&self) -> i32 { 214 unsafe { glib_sys::g_date_time_get_day_of_month(self.to_glib_none().0) } 215 } 216 get_day_of_week(&self) -> i32217 pub fn get_day_of_week(&self) -> i32 { 218 unsafe { glib_sys::g_date_time_get_day_of_week(self.to_glib_none().0) } 219 } 220 get_day_of_year(&self) -> i32221 pub fn get_day_of_year(&self) -> i32 { 222 unsafe { glib_sys::g_date_time_get_day_of_year(self.to_glib_none().0) } 223 } 224 get_hour(&self) -> i32225 pub fn get_hour(&self) -> i32 { 226 unsafe { glib_sys::g_date_time_get_hour(self.to_glib_none().0) } 227 } 228 get_microsecond(&self) -> i32229 pub fn get_microsecond(&self) -> i32 { 230 unsafe { glib_sys::g_date_time_get_microsecond(self.to_glib_none().0) } 231 } 232 get_minute(&self) -> i32233 pub fn get_minute(&self) -> i32 { 234 unsafe { glib_sys::g_date_time_get_minute(self.to_glib_none().0) } 235 } 236 get_month(&self) -> i32237 pub fn get_month(&self) -> i32 { 238 unsafe { glib_sys::g_date_time_get_month(self.to_glib_none().0) } 239 } 240 get_second(&self) -> i32241 pub fn get_second(&self) -> i32 { 242 unsafe { glib_sys::g_date_time_get_second(self.to_glib_none().0) } 243 } 244 get_seconds(&self) -> f64245 pub fn get_seconds(&self) -> f64 { 246 unsafe { glib_sys::g_date_time_get_seconds(self.to_glib_none().0) } 247 } 248 249 #[cfg(any(feature = "v2_58", feature = "dox"))] get_timezone(&self) -> Option<TimeZone>250 pub fn get_timezone(&self) -> Option<TimeZone> { 251 unsafe { from_glib_none(glib_sys::g_date_time_get_timezone(self.to_glib_none().0)) } 252 } 253 get_timezone_abbreviation(&self) -> Option<GString>254 pub fn get_timezone_abbreviation(&self) -> Option<GString> { 255 unsafe { 256 from_glib_none(glib_sys::g_date_time_get_timezone_abbreviation( 257 self.to_glib_none().0, 258 )) 259 } 260 } 261 get_utc_offset(&self) -> TimeSpan262 pub fn get_utc_offset(&self) -> TimeSpan { 263 unsafe { glib_sys::g_date_time_get_utc_offset(self.to_glib_none().0) } 264 } 265 get_week_numbering_year(&self) -> i32266 pub fn get_week_numbering_year(&self) -> i32 { 267 unsafe { glib_sys::g_date_time_get_week_numbering_year(self.to_glib_none().0) } 268 } 269 get_week_of_year(&self) -> i32270 pub fn get_week_of_year(&self) -> i32 { 271 unsafe { glib_sys::g_date_time_get_week_of_year(self.to_glib_none().0) } 272 } 273 get_year(&self) -> i32274 pub fn get_year(&self) -> i32 { 275 unsafe { glib_sys::g_date_time_get_year(self.to_glib_none().0) } 276 } 277 get_ymd(&self) -> (i32, i32, i32)278 pub fn get_ymd(&self) -> (i32, i32, i32) { 279 unsafe { 280 let mut year = mem::uninitialized(); 281 let mut month = mem::uninitialized(); 282 let mut day = mem::uninitialized(); 283 glib_sys::g_date_time_get_ymd(self.to_glib_none().0, &mut year, &mut month, &mut day); 284 (year, month, day) 285 } 286 } 287 is_daylight_savings(&self) -> bool288 pub fn is_daylight_savings(&self) -> bool { 289 unsafe { 290 from_glib(glib_sys::g_date_time_is_daylight_savings( 291 self.to_glib_none().0, 292 )) 293 } 294 } 295 to_local(&self) -> Option<DateTime>296 pub fn to_local(&self) -> Option<DateTime> { 297 unsafe { from_glib_full(glib_sys::g_date_time_to_local(self.to_glib_none().0)) } 298 } 299 300 //pub fn to_timeval(&self, tv: /*Ignored*/&mut TimeVal) -> bool { 301 // unsafe { TODO: call glib_sys:g_date_time_to_timeval() } 302 //} 303 to_timezone(&self, tz: &TimeZone) -> Option<DateTime>304 pub fn to_timezone(&self, tz: &TimeZone) -> Option<DateTime> { 305 unsafe { 306 from_glib_full(glib_sys::g_date_time_to_timezone( 307 self.to_glib_none().0, 308 tz.to_glib_none().0, 309 )) 310 } 311 } 312 to_unix(&self) -> i64313 pub fn to_unix(&self) -> i64 { 314 unsafe { glib_sys::g_date_time_to_unix(self.to_glib_none().0) } 315 } 316 to_utc(&self) -> Option<DateTime>317 pub fn to_utc(&self) -> Option<DateTime> { 318 unsafe { from_glib_full(glib_sys::g_date_time_to_utc(self.to_glib_none().0)) } 319 } 320 compare(&self, dt2: &DateTime) -> i32321 fn compare(&self, dt2: &DateTime) -> i32 { 322 unsafe { 323 glib_sys::g_date_time_compare( 324 ToGlibPtr::<*mut glib_sys::GDateTime>::to_glib_none(self).0 325 as glib_sys::gconstpointer, 326 ToGlibPtr::<*mut glib_sys::GDateTime>::to_glib_none(dt2).0 327 as glib_sys::gconstpointer, 328 ) 329 } 330 } 331 equal(&self, dt2: &DateTime) -> bool332 fn equal(&self, dt2: &DateTime) -> bool { 333 unsafe { 334 from_glib(glib_sys::g_date_time_equal( 335 ToGlibPtr::<*mut glib_sys::GDateTime>::to_glib_none(self).0 336 as glib_sys::gconstpointer, 337 ToGlibPtr::<*mut glib_sys::GDateTime>::to_glib_none(dt2).0 338 as glib_sys::gconstpointer, 339 )) 340 } 341 } 342 hash(&self) -> u32343 fn hash(&self) -> u32 { 344 unsafe { 345 glib_sys::g_date_time_hash( 346 ToGlibPtr::<*mut glib_sys::GDateTime>::to_glib_none(self).0 347 as glib_sys::gconstpointer, 348 ) 349 } 350 } 351 } 352 353 impl PartialOrd for DateTime { 354 #[inline] partial_cmp(&self, other: &Self) -> Option<cmp::Ordering>355 fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { 356 self.compare(other).partial_cmp(&0) 357 } 358 } 359 360 impl Ord for DateTime { 361 #[inline] cmp(&self, other: &Self) -> cmp::Ordering362 fn cmp(&self, other: &Self) -> cmp::Ordering { 363 self.compare(other).cmp(&0) 364 } 365 } 366 367 impl PartialEq for DateTime { 368 #[inline] eq(&self, other: &Self) -> bool369 fn eq(&self, other: &Self) -> bool { 370 self.equal(other) 371 } 372 } 373 374 impl Eq for DateTime {} 375 376 impl hash::Hash for DateTime { 377 #[inline] hash<H>(&self, state: &mut H) where H: hash::Hasher,378 fn hash<H>(&self, state: &mut H) 379 where 380 H: hash::Hasher, 381 { 382 hash::Hash::hash(&self.hash(), state) 383 } 384 } 385 386 unsafe impl Send for DateTime {} 387 unsafe impl Sync for DateTime {} 388