refactor: formatTimestamp func now checks against current year, rather than year to date
This commit is contained in:
parent
f8724162ad
commit
12dff02c6f
@ -22,15 +22,15 @@ export const formatTimestamp = (timestamp: string | number) => {
|
|||||||
? timestamp.replace(" ", "T")
|
? timestamp.replace(" ", "T")
|
||||||
: timestamp
|
: timestamp
|
||||||
);
|
);
|
||||||
const now = new Date();
|
|
||||||
const difference = now.getTime() - date.getTime();
|
|
||||||
|
|
||||||
// Day and short month (example: 21 Oct)
|
// Day and short month (example: 21 Oct)
|
||||||
const result = `${date.getDate()} ${date.toLocaleString("en-GB", { month: "short" })}`
|
const result = `${date.getDate()} ${date.toLocaleString("en-GB", { month: "short" })}`
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
// Difference is less than a year: 'DD MMM, HH:mm'
|
// Difference is less than a year: 'DD MMM, HH:mm'
|
||||||
// Or, difference is more than a year: 'DD MMM YYYY'
|
// 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.getHours().toString().padStart(2, "0")}:${date.getMinutes().toString().padStart(2, "0")}`
|
||||||
: result + ` ${date.getFullYear()}`;
|
: result + ` ${date.getFullYear()}`;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user