ssh-chat/humantime.go
Andrey Petrov 66fee99a81 /uptime and /whois relative timestamps made more precise
Replaced go-humanize dependency with our own logic.

Fixes #259.
2018-01-19 12:35:45 -05:00

20 lines
426 B
Go

package sshchat
import (
"fmt"
"time"
)
// humanSince returns a human-friendly relative time string
func humanSince(d time.Duration) string {
switch {
case d < time.Minute*2:
return fmt.Sprintf("%0.f seconds", d.Seconds())
case d < time.Hour*2:
return fmt.Sprintf("%0.f minutes", d.Minutes())
case d < time.Hour*48:
return fmt.Sprintf("%0.f hours", d.Hours())
}
return fmt.Sprintf("%0.f days", d.Hours()/24)
}