mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 00:38:27 +00:00
[Glitch] feat: use <time> tag
Port e9fe01e2a6 to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
26
app/javascript/flavours/glitch/components/formatted_date.tsx
Normal file
26
app/javascript/flavours/glitch/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();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user