elapsed

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2017 License: MIT Imports: 3 Imported by: 12

README

Elapsed time

GoDoc Build Status Code Coverage Go Report Card

Golang package to return the elapsed time since a given time in a human readable format.

Installation
$ go get -u github.com/rvflash/elapsed
Usage
t := time.Now().Add(-time.Hour)
fmt.Println(elapsed.Time(t))
// Output: 1 hour ago

t = time.Now().Add(-time.Hour * 24 * 3)
fmt.Println(elapsed.Time(t))
// Output:  3 days ago

t, _ = time.Parse("2006-02-01", "2049-08-19")
fmt.Println(elapsed.Time(t))
// Output: not yet

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	NotYet     = `not yet`
	JustNow    = `just now`
	LastMinute = `1 minute ago`
	Minutes    = `%d minutes ago`
	LastHour   = `1 hour ago`
	Hours      = `%d hours ago`
	Yesterday  = `Yesterday`
	Days       = `%d days ago`
	Weeks      = `%d weeks ago`
	Months     = `%d months ago`
	Years      = `%d years ago`
)

Texts to be translated if necessary.

Functions

func Time

func Time(t time.Time) string

Time returns in a human readable format the elapsed time since the given datetime.

Example
package main

import (
	"fmt"
	"time"

	"github.com/rvflash/elapsed"
)

func main() {
	t := time.Now().Add(-time.Hour)
	fmt.Println(elapsed.Time(t))
	t = time.Now().Add(-time.Hour * 24 * 3)
	fmt.Println(elapsed.Time(t))
	t, _ = time.Parse("2006-02-01", "2049-08-19")
	fmt.Println(elapsed.Time(t))
}
Output:

1 hour ago
3 days ago
not yet

Types

This section is empty.

Jump to

Keyboard shortcuts

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