@jeact/timestring
A package based in "s-ago", converts Date objects into human readable strings, with the posibility of translate the results to many languages.
This package bases its functionality in the s-ago
package, but adds suport for more languages, like spanish, portuguese, german, etc.
Instalation
npm i @jeact/timestring
Usage
It has the same usage as the ago
function from s-ago
, but you need to pass a new parameter named lang that must be
a Text Language Package (TLP). This parameter is the language in that you want the human readable text. You
can find them in the TLPS
object, followed by a language codes according to ISO 639-1.
The Following example is also from the s-ago package, but the code is modified to add the new parameter.
let {ago, TLPS} = require('@jeact/timestring');
let now = new Date();
let yesterday = new Date(now.getTime() - (24 * 60 * 60 * 1000));
let hoursAgo = new Date(now.getTime() - (6 * 60 * 60 * 1000));
let yesterday = new Date(now.getTime() - (24 * 60 * 60 * 1000));
let tomorrow = new Date(now.getTime() + (6 * 60 * 60 * 1000));
let inSixHours = new Date(now.getTime() + (6 * 60 * 60 * 1000));
let inTwoWeeks = new Date(now.getTime() + (2 * 7 * 24 * 60 * 60 * 1000));
// present
ago(now, TLPS.EN); // 'just now', the used TLP was EN (english)
// past
ago(yesterday, TLPS.ES); // 'ayer' (yesterday), the used TLP was ES (spanish)
ago(hoursAgo, TLPS.ES); // 'hace 6 horas' (6 hours ago), the used TLP was ES (spanish)
// future
ago(inSixHours, TLPS.IT); // 'in 6 ore' (in 6 hours), the used TLP was IT (italian)
ago(tomorrow, TLPS.IT); // 'domani' (tomorrow), the used TLP was IT (italian)
// max unit
ago(inTwoWeeks, TLPS.FR); // 'dans 2 semaines' (in 2 weeks), the used TLP was FR (french)
ago(inTwoWeeks, TLPS.FR, 'day'); // 'dans 14 jours' (in 14 days), the used TLP was FR (french)
For more information about how ago
works (not including TLPS), visit the
s-ago npm page.
Available Languages
These are the availables TLPS.
- English (
TLPS.EN
) - Spanish (
TLPS.ES
) - Portuguese (
TLPS.PT
) - German (
TLPS.DE
) - French (
TLPS.FR
) - Italian (
TLPS.IT
)
These are TLPS NOT AVAILABLE yet, but that will be in a future (or that's the idea).
- Dutch (
TLPS.NL
) - Polish (
TLPS.PL
) - Ukrainian (
TLPS.UK
) - Russian (
TLPS.RU
) - Turkish (
TLPS.TR
) - Japanese (
TLPS.JA
) - Korean (
TLPS.KO
) - Thai (
TLPS.TH
) - Chinese (
TLPS.ZH
)