common: add json_add_timerel helper.
What changed, and why it matters
This commit simply adds a new helper function for formatting relative time values as JSON numbers. It is a routine, non-security code addition with no bug fix or behavior change to existing features.
No security action needed. Review as normal code-quality change if included in a larger feature.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces json_add_timerel() in common/json_stream.c/h, mirroring the existing json_add_timeabs() helper. It formats a struct timerel as seconds.nanoseconds using the same json_add_primitive_fmt mechanism. No callers are added, no existing logic is modified, and no security-sensitive operations are involved.
Changed components
common/json_stream.ccommon/json_stream.hInspect captured patch +13 / −0
diff --git a/common/json_stream.c b/common/json_stream.c
index 60517b3f..7d1cc92c 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 9cc539e2..bfbb5d0a 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);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.