From 474de83b4dab1668b83c133435e5896ee002b6af Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Thu, 14 Nov 2019 17:10:28 -0500 Subject: Use struct timeval for sub-second precision --- client.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index de3f087..3dce5e9 100644 --- a/client.c +++ b/client.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -394,7 +395,7 @@ static Filter *Filters[] = { }; void clientConsume(struct Client *client) { - time_t time; + struct timeval time; const char *line = ringPeek(&time, client->consumer); if (!line) return; @@ -409,10 +410,13 @@ void clientConsume(struct Client *client) { } if (client->caps & CapServerTime) { - char ts[sizeof("YYYY-MM-DDThh:mm:ss.sssZ")]; - struct tm *tm = gmtime(&time); - strftime(ts, sizeof(ts), "%FT%T.000Z", tm); - clientFormat(client, "@time=%s %s\r\n", ts, line); + char ts[sizeof("YYYY-MM-DDThh:mm:ss")]; + struct tm *tm = gmtime(&time.tv_sec); + strftime(ts, sizeof(ts), "%FT%T", tm); + clientFormat( + client, "@time=%s.%03jdZ %s\r\n", + ts, (intmax_t)(time.tv_usec / 1000), line + ); } else { clientFormat(client, "%s\r\n", line); } -- cgit 1.4.1