feat: use <time>
tag (#34131)
This commit is contained in:
parent
c43508b3e0
commit
e9fe01e2a6
5 changed files with 42 additions and 16 deletions
26
app/javascript/mastodon/components/formatted_date.tsx
Normal file
26
app/javascript/mastodon/components/formatted_date.tsx
Normal file
|
@ -0,0 +1,26 @@
|
|||
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();
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue