Skip to content

Commit

Permalink
refactor win32 timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Feb 7, 2024
1 parent 5d35c3d commit b7d1f56
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/fmt/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,28 +143,23 @@ int fmt_timestamp_us(struct re_printf *pf, void *arg)
{
int h, m, s;
uint64_t us;
#ifdef WIN32
SYSTEMTIME st;

GetSystemTime(&st);

h = st.wHour;
m = st.wMinute;
s = st.wSecond;
us = st.wMilliseconds;
#else
struct timespec tspec;
struct tm tm;

#ifdef WIN32
timespec_get(&tspec, TIME_UTC);
if (!localtime_s(&tm, &tspec.tv_sec))
return EINVAL;
#else
(void)clock_gettime(CLOCK_REALTIME, &tspec);
if (!localtime_r(&tspec.tv_sec, &tm))
return EINVAL;
#endif

h = tm.tm_hour;
m = tm.tm_min;
s = tm.tm_sec;
us = tspec.tv_nsec / 1000;
#endif
(void)arg;

return re_hprintf(pf, "%02u:%02u:%02u.%06llu", h, m, s, us);
Expand Down

0 comments on commit b7d1f56

Please sign in to comment.