2021-06-25 16:08:16 +00:00
|
|
|
// Copyright 2020-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-09-28 23:46:31 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
import moment, { Moment } from 'moment';
|
|
|
|
import { isLinkPreviewDateValid } from '../../linkPreviews/isLinkPreviewDateValid';
|
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
type Props = {
|
2021-06-25 16:08:16 +00:00
|
|
|
date?: null | number;
|
2020-09-28 23:46:31 +00:00
|
|
|
className?: string;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2020-09-28 23:46:31 +00:00
|
|
|
|
|
|
|
export const LinkPreviewDate: React.FC<Props> = ({
|
|
|
|
date,
|
|
|
|
className = '',
|
|
|
|
}: Props) => {
|
|
|
|
const dateMoment: Moment | null = isLinkPreviewDateValid(date)
|
|
|
|
? moment(date)
|
|
|
|
: null;
|
|
|
|
|
|
|
|
return dateMoment ? (
|
|
|
|
<time className={className} dateTime={dateMoment.toISOString()}>
|
|
|
|
{dateMoment.format('ll')}
|
|
|
|
</time>
|
|
|
|
) : null;
|
|
|
|
};
|