signal-desktop/ts/components/conversation/LinkPreviewDate.tsx

28 lines
678 B
TypeScript
Raw Normal View History

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 type { Moment } from 'moment';
import moment from 'moment';
2020-09-28 23:46:31 +00:00
import { isLinkPreviewDateValid } from '../../linkPreviews/isLinkPreviewDateValid';
type Props = {
2021-06-25 16:08:16 +00:00
date?: null | number;
2020-09-28 23:46:31 +00:00
className?: string;
};
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;
};