exfat_fs/
timestamp.rs

1#[derive(Copy, Clone, Debug)]
2pub struct Timestamps {
3    created: Timestamp,
4    modified: Timestamp,
5    accessed: Timestamp,
6}
7
8impl Timestamps {
9    pub fn new(created: Timestamp, modified: Timestamp, accessed: Timestamp) -> Self {
10        Timestamps {
11            created,
12            modified,
13            accessed,
14        }
15    }
16
17    pub fn created(&self) -> &Timestamp {
18        &self.created
19    }
20
21    pub fn modified(&self) -> &Timestamp {
22        &self.modified
23    }
24
25    pub fn accessed(&self) -> &Timestamp {
26        &self.accessed
27    }
28}
29
30#[derive(Copy, Clone, Debug)]
31pub struct Timestamp {
32    timestamp: u32,
33    ms_increment: u8,
34    // Offset from UTC in 15 minute intervals
35    utc_offset: i8,
36}
37
38#[derive(Copy, Clone, Debug)]
39pub struct Date {
40    pub day: u8,
41    pub month: u8,
42    pub year: u16,
43}
44
45#[derive(Copy, Clone, Debug)]
46pub struct Time {
47    pub hour: u8,
48    pub minute: u8,
49    pub second: u8,
50}
51
52impl Timestamp {
53    pub fn new(timestamp: u32, ms_increment: u8, utc_offset: i8) -> Self {
54        Timestamp {
55            timestamp,
56            ms_increment,
57            utc_offset,
58        }
59    }
60
61    pub fn date(&self) -> Date {
62        Date {
63            day: ((self.timestamp >> 16) & 0x1F) as u8,
64            month: ((self.timestamp >> 21) & 0xF) as u8,
65            year: 1980 + ((self.timestamp >> 25) & 0x7F) as u16,
66        }
67    }
68
69    pub fn time(&self) -> Time {
70        Time {
71            second: (self.ms_increment as u16 / 1000) as u8 + (self.timestamp & 0x1F) as u8 * 2,
72            minute: ((self.timestamp >> 5) & 0x3f) as u8,
73            hour: ((self.timestamp >> 11) & 0x1F) as u8,
74        }
75    }
76
77    pub fn utc_offset(&self) -> i8 {
78        self.utc_offset
79    }
80}