mirror of
https://github.com/flarum/framework.git
synced 2025-01-21 21:45:32 +08:00
common: add humanTime helper
This commit is contained in:
parent
8ba86f9c5e
commit
4368dfcc6c
20
js/src/common/helpers/humanTime.tsx
Normal file
20
js/src/common/helpers/humanTime.tsx
Normal 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>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user