ctrlaltdev / justamin

Golang Humanized Duration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duration for Humans

Provided a time.Duration or a time.Time, will return a human representation of the duration.

Installation

go get -u github.com/ctrlaltdev/justamin

How To Use

Humanize a time.Duration:

package main

import (
	"github.com/ctrlaltdev/justamin"
)

func main() {

	// ...
	
	d := time.Duration(49 * 3600 * 1000000000)

	humanized := justamin.Humanize(d)
	// will return "in 2 days"

	// ...
}

Humanize a time.Time (will humanize relatively to time.Now()):

package main

import (
	"github.com/ctrlaltdev/justamin"
)

func main() {

	// ...
	
	t := time.Now().Add(-time.Duration(3600 * 1000000000))

	humanized := justamin.Duration(t)
	// will return "an hour ago"

	// ...
}

About

Golang Humanized Duration

License:Mozilla Public License 2.0


Languages

Language:Go 100.0%