A port of Rails' time_ago_in_words to Golang
Go Makefile
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
cmd/timeago
.travis.yml
LICENSE
Makefile
README.md
timeago.go
timeago_test.go

README.md

timeago

Build Status GoDoc

A port of Rails' time_ago_in_words to Golang

Installation

go get github.com/justincampbell/timeago

Examples

Golang

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

Command-line

$ go get github.com/justincampbell/timeago/cmd/timeago
$ timeago 25s
less than a minute
$ timeago 55m
about 1 hour
$ timeago 72h
3 days