implemented DateTime struct

This commit is contained in:
2025-11-13 05:11:35 +05:00
parent 1775b27980
commit af36bab444
3 changed files with 51 additions and 1 deletions

View File

@@ -44,3 +44,28 @@ void sleepUsec(usec_t time){
void sleepMsec(msec_t time){
sleepNsec(time * M);
}
#define portable_localtime_s(time_t_ptr, tm_ptr) IFWIN(localtime_s(tm_ptr, time_t_ptr), localtime_s(time_t_ptr, tm_ptr))
#define portable_gmtime_s(time_t_ptr, tm_ptr) IFWIN(gmtime_s(tm_ptr, time_t_ptr), gmtime_s(time_t_ptr, tm_ptr))
void DateTime_get(DateTime* dt, bool utc_time){
time_t c_time = time(NULL);
struct tm c_tm;
if(utc_time){
portable_gmtime_s(&c_time, &c_tm);
}
else {
portable_localtime_s(&c_time, &c_tm);
}
struct timespec c_timespec;
clock_gettime(CLOCK_REALTIME, &c_timespec);
dt->t.nsec = c_timespec.tv_nsec;
dt->t.sec = c_timespec.tv_sec;
dt->t.min = c_tm.tm_min;
dt->t.hour = c_tm.tm_hour;
dt->d.month_day = c_tm.tm_mday;
dt->d.month = c_tm.tm_mon;
dt->d.year = c_tm.tm_year;
dt->d.week_day = c_tm.tm_wday;
dt->d.year_day = c_tm.tm_yday;
}