Skip to content
/ timeago Public
forked from SerhiiCho/timeago

100% test covered, fast and lightweight datetime converter that converts given datetime into "n time ago" format from [YEAR-MONTH-DAY HOURS:MINUTES:SECONDS]. Supports Russian and English languages.

License

Notifications You must be signed in to change notification settings

admpub/timeago

 
 

Repository files navigation

Code Coverage Build Status Build Status Scrutinizer Code Quality Go Report Card GitHub

100% test covered, fast and lightweight datetime converter that converts given datetime into "n time ago" format from [YEAR-MONTH-DAY HOURS:MINUTES:SECONDS]. Supports Russian and English languages.

Example usage on repl.it

Configurations

Language

Default language is English. Optionally you can set the language in your application by calling timeago.Set() function and pass the flag "ru" or "en" in your init function.

func init() {
    timeago.Set("language", "ru")
}
Location

Default location is Europe/Kiev. Optionally you can set the location in your application by calling timeago.Set() function and pass the location you need in your init function.

func init() {
    timeago.Set("location", "America/New_York")
}

Please make sure that timezone configuration is correct for your location. It is very important for displaying the correct datetime.

Usage

For outputting post publishing date or something else you can just pass the date to method timeago.Take(). It will count the interval between now and given date and returns converted format.

timeago.Take("2019-10-23 10:46:00") // after 10 seconds outputs: 10 seconds ago

If you want to show last user login like if user is online or not, you can optionally add |online to the datetime string. All it does is just displaying Online if date interval withing 60 seconds.

timeago.Take("2019-10-23 10:46:00|online")

Quick Start

go get -u github.com/SerhiiCho/timeago

About

100% test covered, fast and lightweight datetime converter that converts given datetime into "n time ago" format from [YEAR-MONTH-DAY HOURS:MINUTES:SECONDS]. Supports Russian and English languages.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.4%
  • Makefile 0.6%