Documentation
¶
Overview ¶
Package elapsed return the elapsed time since a given time in a human readable format.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrExists = errors.New("already exists") ErrIncomplete = errors.New("missing translation") ErrISOCode = errors.New("invalid language code") )
Common errors
Functions ¶
func AddTranslation ¶ added in v0.1.0
AddTranslation adds the terms for the given language code. It fails to do it if the language code already exists or if it misses some translation IDs.
func LocalTime ¶ added in v0.1.0
LocalTime returns in a human readable format the elapsed time since the given datetime using the given ISO 639-1 language code.
func Time ¶
Time returns in a human readable format the elapsed time since the given datetime in english. This methods keeps the interface of the first version of the package.
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))
t = time.Now().Add(-time.Hour * 24 * 3)
fmt.Println(elapsed.LocalTime(t, "fr"))
}
Output: 1 hour ago 3 days ago not yet il y a 3 jours
Types ¶
type TrID ¶ added in v0.1.0
type TrID int
TrID is the ID of a translation.
const ( // NotYet is the translation ID for the "not yet" text. NotYet TrID = iota // JustNow is the translation ID for the "just now" text. JustNow // LastMinute is the translation ID for the "1 minute ago" text. LastMinute // Minutes is the translation ID for the "%d minutes ago" text. Minutes // LastHour is the translation ID for the "1 hour ago" text. LastHour // Hours is the translation ID for the "%d hours ago" text. Hours // Yesterday is the translation ID for the "yesterday" text. Yesterday // Days is the translation ID for the "%d days ago" text. Days // Weeks is the translation ID for the "`%d weeks ago" text. Weeks // Months is the translation ID for the "%d months ago" text. Months // Years is the translation ID for the "%d years ago" text. Years )
type Translation ¶ added in v0.1.0
Lists all translations by language code.
Click to show internal directories.
Click to hide internal directories.