summaryrefslogtreecommitdiff
path: root/isisd/isis_misc.c
diff options
context:
space:
mode:
authorMark Stapp <mjs@voltanet.io>2020-03-05 14:06:46 -0500
committerMark Stapp <mjs@voltanet.io>2020-03-09 11:12:32 -0400
commitd0636ead31ccfc9f6c27d02617d5965e3111d4ad (patch)
treef1c383042125411fc44acd65febdf43ce1f1de17 /isisd/isis_misc.c
parent4c2a712d9325070e9ec45c90b1dd11d66e88169e (diff)
lib, *: add a common time interval formatting api
Add a common api that formats a time interval into a string with different output for short and longer intervals. We do this in several places, for cli/ui output. Signed-off-by: Mark Stapp <mjs@voltanet.io>
Diffstat (limited to 'isisd/isis_misc.c')
-rw-r--r--isisd/isis_misc.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/isisd/isis_misc.c b/isisd/isis_misc.c
index 5fa33f5500..96b76da92d 100644
--- a/isisd/isis_misc.c
+++ b/isisd/isis_misc.c
@@ -562,20 +562,12 @@ void vty_multiline(struct vty *vty, const char *prefix, const char *format, ...)
void vty_out_timestr(struct vty *vty, time_t uptime)
{
- struct tm tm;
time_t difftime = time(NULL);
+ char buf[MONOTIME_STRLEN];
+
difftime -= uptime;
- gmtime_r(&difftime, &tm);
-
- if (difftime < ONE_DAY_SECOND)
- vty_out(vty, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
- tm.tm_sec);
- else if (difftime < ONE_WEEK_SECOND)
- vty_out(vty, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour,
- tm.tm_min);
- else
- vty_out(vty, "%02dw%dd%02dh", tm.tm_yday / 7,
- tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour);
- vty_out(vty, " ago");
+ frrtime_to_interval(difftime, buf, sizeof(buf));
+
+ vty_out(vty, "%s ago", buf);
}