lua-timeago

Turn a timestamp into a friendly string of how long ago it was

npm install lua-timeago
4 downloads in the last week
8 downloads in the last month

lua-timeago

Turn a timestamp into a friendly string of how long ago it was

Usage

1. Install

Setup lua-loader and then just npm install lua-timeago

2. Require

local timeago = require("lua-timeago")

3. Have fun

assert(timeago.parse() == "just now")
assert(timeago.parse("2011-06-21") == "2 years")

timeago.setlanguage("nederlands")
assert(timeago.parse() == "zojuist")
assert(timeago.parse("2011-06-21") == "2 jaar")

timeago.setlanguage("english")
timeago.setstyle("short")
assert(timeago.parse() == "now")
assert(timeago.parse("2011-06-21") == "2y")

timeago.setlanguage("nederlands")
assert(timeago.parse() == "net")
assert(timeago.parse("2011-06-21") == "2j")

You can feed it anything that is swallowed by lua-date: date/time strings in different formats, or a lua-date date object. There are two styles: "short" and "long" (default). The default language is "english", and some other languages are readily available. You can provide a new language by passing a table with all the values (see english.lua), but if you do so, don't forget to issue a pull request as well.

License

GNU Lesser General Public License (LGPL)

npm loves you