71 lines
1.5 KiB
C
71 lines
1.5 KiB
C
#pragma once
|
|
|
|
#if __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "std.h"
|
|
|
|
/// nanoseconds
|
|
typedef u64 nsec_t;
|
|
/// microseconds
|
|
typedef u64 usec_t;
|
|
/// miliseconds
|
|
typedef u64 msec_t;
|
|
/// seconds
|
|
typedef u64 sec_t;
|
|
|
|
/// system time now in nanoseconds
|
|
///@return u64 will overflow in 13 years
|
|
nsec_t getTimeNsec();
|
|
|
|
/// system time now in microseconds
|
|
///@return u64 will overflow in 58494 years
|
|
usec_t getTimeUsec();
|
|
|
|
void sleepNsec(nsec_t time);
|
|
void sleepUsec(usec_t time);
|
|
void sleepMsec(msec_t time);
|
|
|
|
|
|
typedef struct Time {
|
|
i32 nsec; /* 0..999_999_999 */
|
|
i8 sec; /* 0..60 leap second??? */
|
|
i8 min; /* 0..59 */
|
|
i8 hour; /* 0..23 */
|
|
} Time;
|
|
|
|
typedef struct Date {
|
|
i8 month_day; /* 1..31 */
|
|
i8 month; /* 1..12 */
|
|
i16 year; /* 1900-xxxx */
|
|
i8 week_day; /* 1..7 */
|
|
i16 year_day; /* 1..366 */
|
|
} Date;
|
|
|
|
typedef struct DateTime {
|
|
Date d;
|
|
Time t;
|
|
} DateTime;
|
|
|
|
void DateTime_get(DateTime* dt, bool utc_time);
|
|
static inline void DateTime_getLocal(DateTime* dt) { DateTime_get(dt, false); }
|
|
static inline void DateTime_getUTC(DateTime* dt) { DateTime_get(dt, true); }
|
|
|
|
// yyyy.MM.dd_HH-mm-ss
|
|
#define FMT_DateTime_fileName "%04i.%02i.%02i_%02i-%02i-%02i"
|
|
// yyyy.MM.dd HH:mm:ss
|
|
#define FMT_DateTime_text "%04i.%02i.%02i %02i:%02i:%02i"
|
|
/*
|
|
USAGE:
|
|
DateTime dt;
|
|
DateTime_getLocal(&dt);
|
|
printf(FMT_DateTime_text, DT_expand(dt));
|
|
*/
|
|
#define DT_expand(dt) dt.d.year, dt.d.month, dt.d.month_day, dt.t.hour, dt.t.min, dt.t.sec
|
|
|
|
|
|
#if __cplusplus
|
|
}
|
|
#endif
|