Fast and lightweight date time package that converts given date into "n time ago" format. The package has many cool features and several supported languages.
- 😎 12 Features
- ⚙️ Configurations
- 🚩 Supported languages
- 👏 Usage
- 🤲 Options
- 🇸🇿 Contribute translation
- 🗒 Release notes
- 🚀 Quick Start
- 📖 Example usage on repl.it
- 🕐 Parses any given date, no matter it is the future date or the past;
- 🕑 Has several options that you can use depending on your use case;
- 🕒 Well tested;
- 🕓 Supports several languages;
- 🕔 Easy to contribute a new language support;
- 🕧 Small codebase;
- 🕖 Frequent small releases without breaking changes;
- 🕗 Can parse Unix timestamp;
- 🕘 Can parse date time string in
YYYY-MM-DD HH:MM:SS
format; - 🕙 Can parse time from
time.Time
go package; - 🕚 All the changes and features are written in the CHANGELOG.md;
- 🕛 Well documented package;
Flag | Language | Code (ISO 639-1) |
---|---|---|
🇬🇧 | English | en |
🇷🇺 | Russian | ru |
🇺🇦 | Ukrainian | uk |
🇳🇱 | Dutch | nl |
Pass the date to timeago.Parse()
function. It counts the interval between current datetime and given datetime and returns parsed string in format x time ago
. The package can work not only with dates in the past but future dates as well. The usage is pretty straight forward.
Method timeago.Parse()
excepts different types of datetime:
int
Unix timestamptime.Time
Type from Go time packagestring
Datetime string in formatYYYY-MM-DD HH:MM:SS
Any other type will trigger a panic.
timeago.Parse("2019-10-23 10:46:00") // string date
timeago.Parse(time.Now()) // time.Time
timeago.Parse(1642607826) // Unix timestamp
pastDate := time.Now().Add(-time.Hour)
res := timeago.Parse(pastDate)
fmt.Println(res) // 1 hour ago
pastDate := time.Now().Add(time.Hour * 2)
res := timeago.Parse(pastDate)
fmt.Println(res) // 2 hours
go get -u github.com/SerhiiCho/timeago