3 use proxmox
::tools
::time
::*;
12 pub fn new(epoch
: i64, utc
: bool
) -> Result
<Self, Error
> {
13 let t
= if utc { gmtime(epoch)? }
else { localtime(epoch)? }
;
17 pub fn into_epoch(mut self) -> Result
<i64, Error
> {
18 let epoch
= if self.utc { timegm(&mut self.t)? }
else { timelocal(&mut self.t)? }
;
22 /// increases the day by 'days' and resets all smaller fields to their minimum
23 pub fn add_days(&mut self, days
: libc
::c_int
) -> Result
<(), Error
> {
24 if days
== 0 { return Ok(()); }
28 self.t
.tm_mday
+= days
;
32 pub fn year(&self) -> libc
::c_int { self.t.tm_year + 1900 }
// see man mktime
33 pub fn hour(&self) -> libc
::c_int { self.t.tm_hour }
34 pub fn min(&self) -> libc
::c_int { self.t.tm_min }
35 pub fn sec(&self) -> libc
::c_int { self.t.tm_sec }
37 // Note: tm_wday (0-6, Sunday = 0) => convert to Sunday = 6
38 pub fn day_num(&self) -> libc
::c_int
{
39 (self.t
.tm_wday
+ 6) % 7
42 pub fn set_time(&mut self, hour
: libc
::c_int
, min
: libc
::c_int
, sec
: libc
::c_int
) -> Result
<(), Error
> {
43 self.t
.tm_hour
= hour
;
49 pub fn set_min_sec(&mut self, min
: libc
::c_int
, sec
: libc
::c_int
) -> Result
<(), Error
> {
55 fn normalize_time(&mut self) -> Result
<(), Error
> {
56 // libc normalizes it for us
60 timelocal(&mut self.t
)?
;
65 pub fn set_sec(&mut self, v
: libc
::c_int
) -> Result
<(), Error
> {
70 pub fn set_min(&mut self, v
: libc
::c_int
) -> Result
<(), Error
> {
75 pub fn set_hour(&mut self, v
: libc
::c_int
) -> Result
<(), Error
> {
80 pub fn set_mday(&mut self, v
: libc
::c_int
) -> Result
<(), Error
> {
85 pub fn set_mon(&mut self, v
: libc
::c_int
) -> Result
<(), Error
> {
90 pub fn set_year(&mut self, v
: libc
::c_int
) -> Result
<(), Error
> {
91 self.t
.tm_year
= v
- 1900;