From 1fefb8044545115cf745f56b90d996a043836a30 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 9 Jul 2026 06:33:19 +0000 Subject: [PATCH] Add t/d for time difference in seconds. --- format.c | 16 ++++++++++++++++ tmux.1 | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/format.c b/format.c index f2bc22a7a..7ec4f06b9 100644 --- a/format.c +++ b/format.c @@ -127,6 +127,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2) #define FORMAT_QUOTE_SHELL_SQ 0x20000000 #define FORMAT_OPTIONS 0x40000000 #define FORMAT_ENVIRON 0x80000000ULL +#define FORMAT_DIFFERENCE 0x100000000ULL /* Limit on recursion. */ #define FORMAT_LOOP_LIMIT 100 @@ -4203,6 +4204,17 @@ format_relative_time(time_t t) return (xstrdup(out)); } +/* Make a time difference in seconds. */ +static char * +format_time_difference(time_t t) +{ + time_t now = time(NULL); + char *out; + + xasprintf(&out, "%ld", (long)now - (long)t); + return (out); +} + /* Find a format entry. */ static char * format_find(struct format_tree *ft, const char *key, uint64_t modifiers, @@ -4287,6 +4299,8 @@ found: return (NULL); if (modifiers & FORMAT_RELATIVE) found = format_relative_time(t); + else if (modifiers & FORMAT_DIFFERENCE) + found = format_time_difference(t); else if (modifiers & FORMAT_PRETTY) found = format_pretty_time(t, 0); else { @@ -5666,6 +5680,8 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen, modifiers |= FORMAT_PRETTY; else if (strchr(fm->argv[0], 'r') != NULL) modifiers |= FORMAT_RELATIVE; + else if (strchr(fm->argv[0], 'd') != NULL) + modifiers |= FORMAT_DIFFERENCE; else if (fm->argc >= 2 && strchr(fm->argv[0], 'f') != NULL) { free(time_format); diff --git a/tmux.1 b/tmux.1 index 593d4de06..dbfb7a30a 100644 --- a/tmux.1 +++ b/tmux.1 @@ -6813,10 +6813,14 @@ Adding will use shorter but less accurate time format for times in the past. .Ql r .Pq Ql t/r -will show the time relative to the current time, for example +will give the time relative to the current time, for example .Ql \&1m or .Ql 2m23s . +.Ql d +.Pq Ql t/d +will give the difference from the time to current time in seconds (future +times are negative). A custom format may be given using an .Ql f suffix (note that