Only process dates with valid dateTime attributes

This commit is contained in:
Jonas Tobias Hopusch 2023-03-11 16:02:59 +01:00
parent 1647746a20
commit ac428b0f6c
Signed by: jotoho
GPG key ID: 913BDF1196DCF600

View file

@ -2,9 +2,11 @@
Array.from(document.getElementsByClassName("relative-timestamp")).forEach( Array.from(document.getElementsByClassName("relative-timestamp")).forEach(
function (timestamp) { function (timestamp) {
timestamp.innerText = new Intl.DateTimeFormat(undefined, { if (timestamp?.dateTime) {
dateStyle: "long", timestamp.innerText = new Intl.DateTimeFormat(undefined, {
timeStyle: "short", dateStyle: "long",
}).format(new Date(timestamp.dateTime)); timeStyle: "short",
}).format(new Date(timestamp.dateTime));
}
} }
); );