Browse Source

rpc: adds json_add_timeiso helper

ppa-prep
Michael Schmoock 4 years ago
committed by neil saitug
parent
commit
4d765003dd
  1. 16
      common/json.c
  2. 5
      common/json.h

16
common/json.c

@ -827,6 +827,22 @@ void json_add_time(struct json_stream *result, const char *fieldname,
json_add_string(result, fieldname, timebuf);
}
void json_add_timeiso(struct json_stream *result,
const char *fieldname,
struct timeabs *time)
{
char iso8601_msec_fmt[sizeof("YYYY-mm-ddTHH:MM:SS.%03dZ")];
char iso8601_s[sizeof("YYYY-mm-ddTHH:MM:SS.nnnZ")];
strftime(iso8601_msec_fmt, sizeof(iso8601_msec_fmt),
"%FT%T.%%03dZ", gmtime(&time->ts.tv_sec));
snprintf(iso8601_s, sizeof(iso8601_s),
iso8601_msec_fmt, (int) time->ts.tv_nsec / 1000000);
json_add_string(result, fieldname, iso8601_s);
}
void json_add_tok(struct json_stream *result, const char *fieldname,
const jsmntok_t *tok, const char *buffer)
{

5
common/json.h

@ -201,6 +201,11 @@ void json_add_timeabs(struct json_stream *result, const char *fieldname,
void json_add_time(struct json_stream *result, const char *fieldname,
struct timespec ts);
/* Add ISO_8601 timestamp string, i.e. "2019-09-07T15:50+01:00" */
void json_add_timeiso(struct json_stream *result,
const char *fieldname,
struct timeabs *time);
/* Add any json token */
void json_add_tok(struct json_stream *result, const char *fieldname,
const jsmntok_t *tok, const char *buffer);

Loading…
Cancel
Save