commit.cocci: refactor code, avoid double rewrite
[git.git] / trace2 / tr2_tbuf.c
blob0844910423679374bcf418bf1abd79c8edddcbe7
1 #include "cache.h"
2 #include "tr2_tbuf.h"
4 void tr2_tbuf_local_time(struct tr2_tbuf *tb)
6 struct timeval tv;
7 struct tm tm;
8 time_t secs;
10 gettimeofday(&tv, NULL);
11 secs = tv.tv_sec;
12 localtime_r(&secs, &tm);
14 xsnprintf(tb->buf, sizeof(tb->buf), "%02d:%02d:%02d.%06ld", tm.tm_hour,
15 tm.tm_min, tm.tm_sec, (long)tv.tv_usec);
18 void tr2_tbuf_utc_time(struct tr2_tbuf *tb)
20 struct timeval tv;
21 struct tm tm;
22 time_t secs;
24 gettimeofday(&tv, NULL);
25 secs = tv.tv_sec;
26 gmtime_r(&secs, &tm);
28 xsnprintf(tb->buf, sizeof(tb->buf),
29 "%4d-%02d-%02d %02d:%02d:%02d.%06ld", tm.tm_year + 1900,
30 tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
31 (long)tv.tv_usec);