mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
rpc: adds json_add_timeiso helper
This commit is contained in:
committed by
neil saitug
parent
67f4970eb1
commit
4d765003dd
@@ -827,6 +827,22 @@ void json_add_time(struct json_stream *result, const char *fieldname,
|
|||||||
json_add_string(result, fieldname, timebuf);
|
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,
|
void json_add_tok(struct json_stream *result, const char *fieldname,
|
||||||
const jsmntok_t *tok, const char *buffer)
|
const jsmntok_t *tok, const char *buffer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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,
|
void json_add_time(struct json_stream *result, const char *fieldname,
|
||||||
struct timespec ts);
|
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 */
|
/* Add any json token */
|
||||||
void json_add_tok(struct json_stream *result, const char *fieldname,
|
void json_add_tok(struct json_stream *result, const char *fieldname,
|
||||||
const jsmntok_t *tok, const char *buffer);
|
const jsmntok_t *tok, const char *buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user