strmap: split create_entry() out of strmap_put()
[git/debian.git] / trace2 / tr2_tbuf.c
blob2498482d9ad82a29b2e734b0d726599d594a20c6
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_datetime_extended(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-%02dT%02d:%02d:%02d.%06ldZ", 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);
34 void tr2_tbuf_utc_datetime(struct tr2_tbuf *tb)
36 struct timeval tv;
37 struct tm tm;
38 time_t secs;
40 gettimeofday(&tv, NULL);
41 secs = tv.tv_sec;
42 gmtime_r(&secs, &tm);
44 xsnprintf(tb->buf, sizeof(tb->buf), "%4d%02d%02dT%02d%02d%02d.%06ldZ",
45 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
46 tm.tm_min, tm.tm_sec, (long)tv.tv_usec);