Merge branch 'master' into vfs-dev
[lunaix-os.git] / lunaix-os / includes / lunaix / clock.h
1 #ifndef __LUNAIX_CLOCK_H
2 #define __LUNAIX_CLOCK_H
3
4 #include <stdint.h>
5
6 typedef uint32_t time_t;
7
8 typedef struct
9 {
10     uint32_t year; // use int32 as we need to store the 4-digit year
11     uint8_t month;
12     uint8_t day;
13     uint8_t weekday;
14     uint8_t hour;
15     uint8_t minute;
16     uint8_t second;
17 } datetime_t;
18
19 void
20 clock_init();
21
22 void
23 clock_walltime(datetime_t* datetime);
24
25 int
26 clock_datatime_eq(datetime_t* a, datetime_t* b);
27
28 /**
29  * @brief 返回当前系统时间,即自从开机到当前时刻的毫秒时。
30  *
31  * @return time_t
32  */
33 time_t
34 clock_systime();
35
36 time_t
37 clock_unixtime();
38
39 static inline time_t
40 clock_tounixtime(datetime_t* dt)
41 {
42     return (dt->year - 1970) * 31556926u + (dt->month - 1) * 2629743u +
43            (dt->day - 1) * 86400u + (dt->hour - 1) * 3600u +
44            (dt->minute - 1) * 60u + dt->second;
45 }
46
47 #endif /* __LUNAIX_CLOCK_H */