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

28 lines
677 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
2022-11-18 00:45:19 +00:00
export function LinkPreviewDate({
2020-09-28 23:46:31 +00:00
date,
className = '',
2022-11-18 00:45:19 +00:00
}: Props): JSX.Element | null {
2020-09-28 23:46:31 +00:00
const dateMoment: Moment | null = isLinkPreviewDateValid(date)
? moment(date)
: null;
return dateMoment ? (
<time className={className} dateTime={dateMoment.toISOString()}>
{dateMoment.format('ll')}
</time>
) : null;
2022-11-18 00:45:19 +00:00
}