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
use crate::FileInfo;
use glib::translate::*;
use std::mem;
use std::time::{Duration, SystemTime};
impl FileInfo {
#[cfg_attr(feature = "v2_62", deprecated)]
#[doc(alias = "g_file_info_get_modification_time")]
#[doc(alias = "get_modification_time")]
pub fn modification_time(&self) -> SystemTime {
unsafe {
let mut result = mem::MaybeUninit::uninit();
ffi::g_file_info_get_modification_time(self.to_glib_none().0, result.as_mut_ptr());
let result = result.assume_init();
if result.tv_sec > 0 {
let duration = Duration::from_secs(result.tv_sec as u64)
+ Duration::from_millis(result.tv_usec as u64);
SystemTime::UNIX_EPOCH + duration
} else {
let duration = Duration::from_secs((-result.tv_sec) as u64)
+ Duration::from_millis(result.tv_usec as u64);
SystemTime::UNIX_EPOCH - duration
}
}
}
#[cfg_attr(feature = "v2_62", deprecated)]
#[doc(alias = "g_file_info_set_modification_time")]
pub fn set_modification_time(&self, mtime: SystemTime) {
let diff = mtime
.duration_since(SystemTime::UNIX_EPOCH)
.expect("failed to convert time");
unsafe {
ffi::g_file_info_set_modification_time(
self.to_glib_none().0,
mut_override(&glib::ffi::GTimeVal {
tv_sec: diff.as_secs() as _,
tv_usec: diff.subsec_micros() as _,
}),
);
}
}
}