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.
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")
}
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.
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")
go get -u github.com/SerhiiCho/timeago