format time

This commit is contained in:
Gustavo Chain 2020-02-13 18:47:05 +01:00
parent be7651f415
commit f982b9f277
No known key found for this signature in database
GPG Key ID: DA7C1746DC118A46

View File

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