Skip to content
forked from SerhiiCho/timeago

Fast and lightweight datetime package that converts given datetime into "n time ago" format

License

Notifications You must be signed in to change notification settings

dragstor/timeago

 
 

Repository files navigation

golang

GoReportCard example Code Coverage Build Status Build Status Scrutinizer Code Quality GitHub

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

  • 🕐 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;

🚩 Supported languages

Flag Language Code (ISO 639-1)
🇬🇧 English en
🇷🇺 Russian ru
🇺🇦 Ukrainian uk
🇳🇱 Dutch nl

👏 Usage

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.

Allowed types

Method timeago.Parse() excepts different types of datetime:

  • int Unix timestamp
  • time.Time Type from Go time package
  • string Datetime string in format YYYY-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

Usage with the date in the past

pastDate := time.Now().Add(-time.Hour)

res := timeago.Parse(pastDate)

fmt.Println(res) // 1 hour ago

Usage with the date in the future

pastDate := time.Now().Add(time.Hour * 2)

res := timeago.Parse(pastDate)

fmt.Println(res) // 2 hours

🚀 Quick Start

go get -u github.com/SerhiiCho/timeago

About

Fast and lightweight datetime package that converts given datetime into "n time ago" format

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%