refactor: formatTimestamp func now checks against current year, rather than year to date

This commit is contained in:
Corban-Lee Jones 2025-04-28 10:29:10 +01:00
parent f8724162ad
commit 12dff02c6f

View File

@ -22,15 +22,15 @@ export const formatTimestamp = (timestamp: string | number) => {
? timestamp.replace(" ", "T")
: timestamp
);
const now = new Date();
const difference = now.getTime() - date.getTime();
// Day and short month (example: 21 Oct)
const result = `${date.getDate()} ${date.toLocaleString("en-GB", { month: "short" })}`
const now = new Date();
// Difference is less than a year: 'DD MMM, HH:mm'
// Or, difference is more than a year: 'DD MMM YYYY'
return difference < 31536000000
return now.getFullYear() === date.getFullYear()
? result + `, ${date.getHours().toString().padStart(2, "0")}:${date.getMinutes().toString().padStart(2, "0")}`
: result + ` ${date.getFullYear()}`;
}