common: add humanTime helper

This commit is contained in:
David Sevilla Martin 2020-02-07 09:14:33 -05:00
parent 8ba86f9c5e
commit 4368dfcc6c
No known key found for this signature in database
GPG Key ID: F764F1417E16B15F

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>
);
}