1
0
mirror of https://github.com/flarum/core.git synced 2025-08-04 15:37:51 +02:00

common: add humanTime helper

This commit is contained in:
David Sevilla Martin
2020-02-07 09:14:33 -05:00
parent 8ba86f9c5e
commit 4368dfcc6c

View File

@@ -0,0 +1,20 @@
import humanTimeUtil from '../utils/humanTime';
/**
* The `humanTime` helper displays a time in a human-friendly time-ago format
* (e.g. '12 days ago'), wrapped in a <time> tag with other information about
* the time.
*/
export default function humanTime(time: Date) {
const mo = dayjs(time);
const datetime = mo.format();
const full = mo.format('LLLL');
const ago = humanTimeUtil(time);
return (
<time pubdate datetime={datetime} title={full} data-humantime>
{ago}
</time>
);
}