Code Monkey home page Code Monkey logo

timeago's Introduction

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

timeago's People

Contributors

serhiicho avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.