mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-12 03:07:28 +03:00
18 lines
577 B
TypeScript
18 lines
577 B
TypeScript
import { parseISO, format as formatDate, getUnixTime, formatDistance } from 'date-fns';
|
|
import { isDateObject } from './helpers/date';
|
|
|
|
export interface DateProps {
|
|
date: Date | string;
|
|
format?: string;
|
|
relative?: boolean;
|
|
}
|
|
|
|
export const Time = ({ date, format = 'yyyy-MM-dd HH:mm', relative = false }: DateProps) => {
|
|
const dateObject = isDateObject(date) ? date : parseISO(date);
|
|
|
|
return (
|
|
<time dateTime={`${getUnixTime(dateObject)}000`}>
|
|
{relative ? `${formatDistance(new Date(), dateObject)} ago` : formatDate(dateObject, format)}
|
|
</time>
|
|
);
|
|
};
|