From f982b9f277fb7f935a503953d48cbfb996143c4a Mon Sep 17 00:00:00 2001 From: Gustavo Chain Date: Thu, 13 Feb 2020 18:47:05 +0100 Subject: [PATCH] format time --- ui/ui.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ui/ui.go b/ui/ui.go index 9460f95..8bdb5dd 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -213,7 +213,7 @@ func printBlock(n int, blocks []*client.Block) []byte { " ", " ", " ", - white(" %d secs ago ", ago), + white(" %s ago ", fmtSeconds(ago)), " ", } @@ -226,3 +226,14 @@ func printBlock(n int, blocks []*client.Block) []byte { fmt.Fprintf(buf, strings.Join(lines, "\n")) return buf.Bytes() } + +func fmtSeconds(s int64) string { + if s < 60 { + return "< 1 minute" + } else if s < 120 { + return fmt.Sprintf("1 minute") + } else if s < 3600 { + return fmt.Sprintf("%d minutes", s/60) + } + return fmt.Sprintf("%d hours", s/3600) +}