Skip to content

timeago-js is a <1 kb Javascript library used to automatically update date elements with user friendly statements (just now, n seconds ago etc.)

License

Notifications You must be signed in to change notification settings

tekinosman/timeago-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timeago-js

timeago-js is a small (<1 kb) Javascript library with multilingual support that automatically updates date elements with user friendly statements, such as "just now", "n seconds ago" etc. It offers mul

How to install

  1. git clone https://github.com/osmanjtekin/timeago-js.git

  2. Add type="module" to the script tag, and import {timeago} from "./helpers/timeago-js/timeago.js" to the js file.

Usage

By default, the timeago() function:

  • Targets all elements with the time class.
  • Retrieves the timestamp value (in seconds) from the data-timestamp attribute of the targeted elements.
  • Sets the refresh rate to 30 seconds
  • Sets the language to English

Custom values can be set with: timeago(<class_name>, <refresh_rate>, <language>).

Adding a language

To include a new language, add a new array containing the localized string to languages.js:

const <language>_<territory> = [
    "<now|one second ago>",    "<seconds ago>",
    "<one minute ago>",        "<minutes ago>",
    "<one hour ago>",          "<hours ago>",
    "<one day ago>",           "<days ago>",
    "<one week ago>",          "<weeks ago>",
    "<one month ago>",         "<months ago>",
    "<one year ago>",          "<years ago>"
  ];

Where:

Make sure you add <language>_<territory> to export.

Then either open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

timeago-js is a <1 kb Javascript library used to automatically update date elements with user friendly statements (just now, n seconds ago etc.)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published