A port of Rails' time_ago_in_words
to Golang
go get github.com/justincampbell/timeago
package main
import (
"fmt"
"time"
"github.com/justincampbell/timeago"
)
func main() {
var d time.Duration
d, _ = time.ParseDuration("25s")
fmt.Println(timeago.FromDuration(d))
d, _ = time.ParseDuration("55m")
fmt.Println(timeago.FromDuration(d))
d, _ = time.ParseDuration("72h")
fmt.Println(timeago.FromDuration(d))
}
$ go run main.go
less than a minute
about 1 hour
3 days
$ go get github.com/justincampbell/timeago/cmd/timeago
$ timeago 25s
less than a minute
$ timeago 55m
about 1 hour
$ timeago 72h
3 days