mirror of
https://github.com/apricote/apricote.de.git
synced 2026-01-13 20:51:02 +00:00
fix: improve relative time display
This commit is contained in:
parent
d6a70f5436
commit
d8f4a427f0
1 changed files with 14 additions and 3 deletions
|
|
@ -16,13 +16,24 @@
|
||||||
try {
|
try {
|
||||||
date = new Date(element.innerText);
|
date = new Date(element.innerText);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Element does have a proper date");
|
console.error("Element does not have a proper date");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const diffMs = date - new Date();
|
const diffMs = date - new Date();
|
||||||
const daysSince = diffMs / 1000 / 60 / 60 / 24;
|
const hoursSince = diffMs / 1000 / 60 / 60;
|
||||||
const formatted = formatter.format(daysSince, "days");
|
const daysSince = hoursSince / 24;
|
||||||
|
|
||||||
|
let formatted = "";
|
||||||
|
|
||||||
|
if (daysSince > 1) {
|
||||||
|
formatted = formatter.format(daysSince, "days");
|
||||||
|
} else if (hoursSince > 1) {
|
||||||
|
formatted = formatter.format(daysSince, "hours");
|
||||||
|
} else {
|
||||||
|
formatted = "Just Now!";
|
||||||
|
}
|
||||||
|
|
||||||
const capitalized =
|
const capitalized =
|
||||||
formatted.charAt(0).toUpperCase() + formatted.slice(1);
|
formatted.charAt(0).toUpperCase() + formatted.slice(1);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue