File_system/
Time.rs

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
use core::fmt::{self, Display, Formatter};

use Shared::{Duration_type, Unix_to_human_time};

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct Time_type {
    Seconds: u64,
}

impl Time_type {
    pub const fn New(Seconds: u64) -> Self {
        Self { Seconds }
    }

    pub const fn As_u64(self) -> u64 {
        self.Seconds
    }
}

impl From<Duration_type> for Time_type {
    fn from(Duration: Duration_type) -> Self {
        Self {
            Seconds: Duration.As_seconds(),
        }
    }
}

impl From<Time_type> for Duration_type {
    fn from(Time: Time_type) -> Self {
        Duration_type::New(Time.Seconds, 0)
    }
}

impl Display for Time_type {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        let (Year, Month, Day, Hour, Minute, Second) = Unix_to_human_time(self.Seconds as i64);

        write!(
            f,
            "{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
            Year, Month, Day, Hour, Minute, Second
        )
    }
}