Package that provides you with a method that describes the time between `time.Now()` and a given time
Go
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.travis.yml
README.md
lang_english.go
timeagoo.go
timeagoo_test.go

README.md

timeagoo

Build Status

This package provides you with a method that describes the time between time.Now() and a given time. It's an alternative package to justincampbell/timeago.

Dialogs describing the time difference

↓ Formatted date (eg. Mon Jan 2 2015)
↓ Yesterday hh:mm 
↓ Today hh:mm
↓ About %s minutes ago 
↓ About one minute ago 
↓ About %s seconds ago
↓ Recently
- Now
↑ Soon
↑ In about %s seconds
↑ In about one minute
↑ In about %s minutes
↑ Today hh:mm
↑ Tomorrow hh:mm
↑ Formatted date (eg. Mon Jan 2 2021)

API

func Format(time time.Time, dialogs timeagoo.language.Dialogs) string

package main

import (
    "github.com/victorjonsson/timeagoo"
    ...
)

...

func formatWhenIncidentOccurred(i Incident) {    
    return timeagoo.Format(i.time, timeagoo.EnglishDialogs{})
}

Multilingual support

The package comes with an English translation of all dialogs. You can use another language by implementing the Dialogs interface.

import "time"

type swedishDialogs struct {
}

func (swedishDialogs) Recently() string {
    return "Nyligen";
}
...

func FormatTimeagoo(t time.Time) string {
    return timeagoo.Format(t, swedishDialogs{})
}