dbsdk_rs/
clock.rs

1use core::fmt::Display;
2
3use crate::db_internal::{clock_getTimestamp, clock_timestampToDatetime};
4
5#[repr(C)]
6#[derive(Clone, Copy, Debug)]
7pub struct DateTime {
8    pub year: u16,
9    pub month: u8,
10    pub day: u8,
11    pub hour: u8,
12    pub minute: u8,
13    pub second: u8,
14}
15
16impl Display for DateTime {
17    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
18        write!(f, "{}/{}/{} {:02}:{:02}:{:02}", self.month, self.day, self.year, self.hour, self.minute, self.second)
19    }
20}
21
22/// Get the current console time
23pub fn get_time() -> DateTime {
24    unsafe {
25        let ts = clock_getTimestamp();
26        let mut dt = DateTime {
27            year: 0,
28            month: 0,
29            day: 0,
30            hour: 0,
31            minute: 0,
32            second: 0
33        };
34        clock_timestampToDatetime(ts, &mut dt);
35        return dt;
36    }
37}