From 80309dfbe6aedf003d2198da3d8808d1946224e9 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 13 Jun 2025 14:42:50 +0930 Subject: [PATCH] common: add json_add_timerel helper. Signed-off-by: Rusty Russell --- common/json_stream.c | 8 ++++++++ common/json_stream.h | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/common/json_stream.c b/common/json_stream.c index 60517b3fb..7d1cc92cb 100644 --- a/common/json_stream.c +++ b/common/json_stream.c @@ -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) { diff --git a/common/json_stream.h b/common/json_stream.h index 9cc539e29..bfbb5d0a7 100644 --- a/common/json_stream.h +++ b/common/json_stream.h @@ -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);