Skip to content

Commit

Permalink
format time
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Chain committed Feb 13, 2020
1 parent be7651f commit f982b9f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func printBlock(n int, blocks []*client.Block) []byte {
" ",
" ",
" ",
white(" %d secs ago ", ago),
white(" %s ago ", fmtSeconds(ago)),
" ",
}

Expand All @@ -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)
}

0 comments on commit f982b9f

Please sign in to comment.