|
1
|
import React from "react" |
|
2
|
|
|
3
|
const DATE_REGEX = /^[a-zA-Z]+ (?<month>[a-zA-Z]+)/ |
|
4
|
|
|
5
|
type EditDateProps = { |
|
6
|
date: string |
|
7
|
} |
|
8
|
|
|
9
|
export const EditDate = ({ date }: EditDateProps) => { |
|
10
|
const today = new Date() |
|
11
|
const dateObj = new Date(date) |
|
12
|
if (isNaN(dateObj.getTime())) { |
|
13
|
return <></> |
|
14
|
} |
|
15
|
const formattedDate = dateObj.toString() |
|
16
|
const dateMatch = DATE_REGEX.exec(formattedDate) |
|
17
|
|
|
18
|
if (!dateMatch?.groups?.month) { |
|
19
|
return <></> |
|
20
|
} |
|
21
|
|
|
22
|
return ( |
|
23
|
<> |
|
24
|
<span className="text-compact-small-plus" data-testid="edit-date"> |
|
25
|
Edited {dateMatch.groups.month} {dateObj.getDate()} |
|
26
|
{dateObj.getFullYear() !== today.getFullYear() |
|
27
|
? `, ${dateObj.getFullYear()}` |
|
28
|
: ""} |
|
29
|
</span> |
|
30
|
<span className="text-compact-small">·</span> |
|
31
|
</> |
|
32
|
) |
|
33
|
} |