Skip to content

Commit dd68a20

Browse files
committed
common: add json_add_timerel helper.
Signed-off-by: Rusty Russell <[email protected]>
1 parent 40d319b commit dd68a20

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

common/json_stream.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@ void json_add_timeabs(struct json_stream *result, const char *fieldname,
372372
(u64)t.ts.tv_sec, (u64)t.ts.tv_nsec);
373373
}
374374

375+
void json_add_timerel(struct json_stream *result, const char *fieldname,
376+
struct timerel t)
377+
{
378+
json_add_primitive_fmt(result, fieldname,
379+
"%" PRIu64 ".%09" PRIu64,
380+
(u64)t.ts.tv_sec, (u64)t.ts.tv_nsec);
381+
}
382+
375383
void json_add_timestr(struct json_stream *result, const char *fieldname,
376384
struct timespec ts)
377385
{

common/json_stream.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,14 @@ void json_add_hex_talarr(struct json_stream *result,
253253
const char *fieldname,
254254
const tal_t *data);
255255

256+
/* '"fieldname" : 1749785122.000000001 */
256257
void json_add_timeabs(struct json_stream *result, const char *fieldname,
257258
struct timeabs t);
258259

260+
/* '"fieldname" : 1.000000001 */
261+
void json_add_timerel(struct json_stream *result, const char *fieldname,
262+
struct timerel t);
263+
259264
/* used in log.c and notification.c*/
260265
void json_add_timestr(struct json_stream *result, const char *fieldname,
261266
struct timespec ts);

0 commit comments

Comments
 (0)