Files
mastodon/app/javascript/flavours/glitch/components/formatted_date.tsx
scarf d5ff3ee4a0 [Glitch] feat: use <time> tag
Port e9fe01e2a6 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2025-03-27 19:42:37 +01:00

27 lines
587 B
TypeScript

import type { ComponentProps } from 'react';
import { FormattedDate } from 'react-intl';
export const FormattedDateWrapper = (
props: ComponentProps<typeof FormattedDate> & { className?: string },
) => (
<FormattedDate {...props}>
{(date) => (
<time dateTime={tryIsoString(props.value)} className={props.className}>
{date}
</time>
)}
</FormattedDate>
);
const tryIsoString = (date?: string | number | Date): string => {
if (!date) {
return '';
}
try {
return new Date(date).toISOString();
} catch {
return date.toString();
}
};