catamphetamine / javascript-time-ago

International highly customizable relative date/time formatting

Home Page:https://catamphetamine.gitlab.io/react-time-ago/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible a mix between canonical and 'time' style?

manueledones opened this issue · comments

Hi,

I'd like to use this lib to explain a duration between two dates in the past, few seconds one from the other, but both distant for example few years ago.

I get the difference between the two dates and use it as the input to the format method.

If I use the default style, the output would be "just now", because the distance between the two dates is short, but the two dates are in the past, so 'just now' is not acceptable.

If I use the canonical style, the output would be like '10 seconds ago', but I would like to remove that 'ago'.

So, something like 'few seconds', '5 seconds', 'few minutes', 'one hour', etc, would be perfect.

I think it's a mix between a canonical style and the 'time' option.

I hope I made myself clear...

Thanks!

If I use the default style, the output would be "just now", because the distance between the two dates is short, but the two dates are in the past, so 'just now' is not acceptable.

Then use a custom "grading" scale.

If I use the canonical style, the output would be like '10 seconds ago', but I would like to remove that 'ago'.

Then use -short style.

Currently styles aren't exported.
They can be imported via something like import { defaultStyle } from 'javascript-time-ago/commonjs/style', and then replace flavour with "long-short".
https://unpkg.com/browse/javascript-time-ago@2.0.4/modules/style/default.js
flavour will probably be renamed into something else in 3.x, but in 2.x — use flavour.

I think to have found the right configuration with this settings, removing the 'now' unit:

format(date, { flavour: ['long-time', 'short'], units: ["second", "minute", "hour", "day", "week", "month", "year"] })

With this config, the flavour long-time is applied (so that 'ago' is not present), and the "just now" is skipped by removing the "now" unit.

Maybe it will fail when the data is lower than a second, that's not my case so far...

What do you think? ;)

Maybe it will fail when the data is lower than a second, that's not my case so far...

It won't, it'll just show 0 seconds.

What do you think?

Looks ok.