common: add json_add_timerel helper.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2025-06-13 14:42:50 +09:30
parent 052f36cf2e
commit 80309dfbe6
2 changed files with 13 additions and 0 deletions

View File

@@ -372,6 +372,14 @@ void json_add_timeabs(struct json_stream *result, const char *fieldname,
(u64)t.ts.tv_sec, (u64)t.ts.tv_nsec);
}
void json_add_timerel(struct json_stream *result, const char *fieldname,
struct timerel t)
{
json_add_primitive_fmt(result, fieldname,
"%" PRIu64 ".%09" PRIu64,
(u64)t.ts.tv_sec, (u64)t.ts.tv_nsec);
}
void json_add_timestr(struct json_stream *result, const char *fieldname,
struct timespec ts)
{

View File

@@ -253,9 +253,14 @@ void json_add_hex_talarr(struct json_stream *result,
const char *fieldname,
const tal_t *data);
/* '"fieldname" : 1749785122.000000001 */
void json_add_timeabs(struct json_stream *result, const char *fieldname,
struct timeabs t);
/* '"fieldname" : 1.000000001 */
void json_add_timerel(struct json_stream *result, const char *fieldname,
struct timerel t);
/* used in log.c and notification.c*/
void json_add_timestr(struct json_stream *result, const char *fieldname,
struct timespec ts);