timeago

package module
v0.0.0-...-027f403 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2016 License: MIT Imports: 4 Imported by: 9

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromDuration

func FromDuration(d time.Duration) string

FromDuration returns a friendly string representing an approximation of the given duration

func FromTime

func FromTime(t time.Time) string

FromTime returns a friendly string representing the approximate difference from the given time and time.Now()

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL