Coder Social home page Coder Social logo

tinyago-js's Introduction

TinyAgo.js

TinyAgo.js is a tiny (180 bytes when minified) JavaScript library that converts timestamps into relative time (a.k.a. "time ago").

Usage

The library provides one function ago(), which expects an argument that is a timestamp in milliseconds (such as the return value of the Date.getTime() method), and returns a string with the relative time:

var d = new Date('January 1, 2014');
console.log(ago(d.getTime())); // -> '7 months' (assuming it's August 2014)

As shown in the above example, the function does not return the 'ago' suffix. This is left as an exercise for the reader.

Dates in the future

The function assumes the timestamp is in the past, but with a little wrapper it can also work with future dates:

function agofromnow(v) {
    if (v > Date.now())
        return ago(2 * Date.now() - v) + ' from now';
    else
        return ago(v) + ' ago';
}

tinyago-js's People

Contributors

odyniec avatar

Stargazers

bahlemakhaya avatar Fahad Raazaq avatar Thiti Yamsung avatar Abdullah avatar Bilawal Ali avatar Antonis Triantafyllopoulos avatar Carlos Eugenio Torres avatar Christian Gogstad Eide avatar hack/err avatar Lan Qingyong avatar Leon Sorokin avatar Wesley Luyten avatar 49fl avatar Dmitriy Nyashkin avatar Jens Törnell avatar Jack avatar Ilya Oblomov avatar Hunnain Pasha avatar Carol avatar mukhtar avatar Thomas avatar Inzamam Malik avatar Alexander Elgin avatar Yacine Rezgui avatar Phil Kaufmann avatar Daniel Waardal avatar Florian Warninghoff avatar Ben Smith avatar Ravinder Kumar avatar

Watchers

Leon Sorokin avatar  avatar James Cloos avatar Jack avatar  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.