Fix singular of time ago display

This commit is contained in:
Max L. 2023-11-23 20:44:42 +01:00
parent 3ffdeabf33
commit df73c736dd
No known key found for this signature in database
GPG key ID: 2F963B95632B8467

View file

@ -17,20 +17,32 @@ const secondsAgo = date => Math.floor((new Date() - date) / 1000);
const timeAgo = function(seconds) {
// An array of intervals for years, months, days, hours, and minutes.
const intervals = [
{ limit: 31536000, text: 'Jahren' },
{ limit: 2592000, text: 'Monaten' },
{ limit: 86400, text: 'Tagen' },
{ limit: 3600, text: 'Stunden' },
{ limit: 60, text: 'Minuten' }
{ limit: 31536000, singular: 'Jahre', plural: 'Jahren' },
{ limit: 2592000, singular: 'Monat', plural: 'Monaten' },
{ limit: 86400, singular: 'Tag', plural: 'Tagen' },
{ limit: 3600, singular: 'Stunde', plural: 'Stunden' },
{ limit: 60, singular: 'Minute', plural: 'Minuten' }
];
// Loop through the intervals to find which one is the best fit.
for (let interval of intervals) {
if (seconds >= interval.limit) {
return "Vor " + Math.floor(seconds / interval.limit) + ` ${interval.text}`;
let amount = Math.floor(seconds / interval.limit);
let text;
if (amount !== 1) {
text = interval.plural;
} else {
text = interval.singular;
}
return `Vor ${amount} ${text}`;
}
}
return "Vor " + Math.floor(seconds) + " Sekunden";
let text = "Sekunde";
let amount = Math.floor(seconds);
if (amount !== 1) {
text += "n";
}
return `Vor ${amount} ${text}`;
};
let includeReplies;