Improvements for display #1
1 changed files with 19 additions and 7 deletions
26
script.js
26
script.js
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue