hl-ago

1.0.3 • Public • Published

Ago

Ago is a simple tool for calculating how long ago a date was.

 
var Ago = require("hl-ago");
 
var ago = new Ago({
  date: new Date("1993/10/15 09:05:10 pm"),
  lang: 'en-US',
  hourFormat: 12
});
 
ago.getFullDate(); // => October 15th 1993 09:05:10 pm
ago.getDate();     // => October 15th 1993
ago.getTime();     // => 09:05:10 pm
ago.toString();    // => 2 decades ago
                   //    (2 decades ago from 2015)
 

API

Ago(options)

The constructor.

 
var Ago = require("hl-ago");
 
// This are the only three options.
var options = {
  date: new Date("1993/10/15 09:05:10 pm"), // date to work with.
  lang: 'en-US', // language to use.
  hourFormat: 12 // hour format 24 or 12
};
 
var ago = new Ago(options);
 

Ago.getFullDate()

This method returns a string with the full date.

 
ago.getFullDate(); // => October 15th 1993 09:05:10 pm
 

Ago.getDate()

This method returns a string just with the date.

 
ago.getDate();     // => October 15th 1993
 

Ago.getTime()

This method returns a string just with the time.

 
ago.getTime();     // => 09:05:10 pm
 

Ago.ago()

This method returns a string telling how long ago was a date.

 
ago.ago();    // => 2 decades ago
              //    (2 decades ago from 2015)
 

Ago.toString()

Same as Ago.ago().

 
ago.toString(); // => 2 decades ago
ago + "";       // => 2 decades ago
                //    (2 decades ago from 2015)
 

Ago.setLanguage(language)

// TODO: Add documentation

Ago.getLanguage()

// TODO: Add documentation

Ago.setHourFormat(format)

// TODO: Add documentation

Ago.getHourFormat()

// TODO: Add documentation

Ago.loadCustomLanguages(languages)

// TODO: Add documentation

LICENSE

MIT

Dependencies (1)

Dev Dependencies (1)

Package Sidebar

Install

npm i hl-ago

Weekly Downloads

2

Version

1.0.3

License

MIT

Last publish

Collaborators

  • modestofiguereo