extend utils.ago to handle dates beyond 31 days

This commit is contained in:
Martin Zimmermann 2013-09-12 17:28:13 +02:00
parent 63f03e1111
commit 27ba6d795f

View File

@ -20,18 +20,20 @@ define({
var diff = (((new Date()).getTime() - date.getTime()) / 1000), var diff = (((new Date()).getTime() - date.getTime()) / 1000),
day_diff = Math.floor(diff / 86400); day_diff = Math.floor(diff / 86400);
if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31) if (isNaN(day_diff) || day_diff < 0)
return; return;
return day_diff == 0 && ( return day_diff == 0 && (
diff < 60 && "eben jetzt" || diff < 60 && "eben jetzt" ||
diff < 120 && "vor einer Minute" || diff < 120 && "vor einer Minute" ||
diff < 3600 && "vor " + Math.floor(diff / 60) + " Minuten" || diff < 3600 && "vor " + Math.floor(diff / 60) + " Minuten" ||
diff < 7200 && "vor einer Stunde" || diff < 7200 && "vor einer Stunde" ||
diff < 86400 && "vor " + Math.floor(diff / 3600) + " Stunden") || diff < 86400 && "vor " + Math.floor(diff / 3600) + " Stunden") ||
day_diff == 1 && "Gestern" || day_diff == 1 && "Gestern" ||
day_diff < 7 && "vor " + day_diff + " Tagen" || day_diff < 7 && "vor " + day_diff + " Tagen" ||
day_diff < 31 && "vor " + Math.ceil(day_diff / 7) + " Wochen"; day_diff < 31 && "vor " + Math.ceil(day_diff / 7) + " Wochen" ||
day_diff < 365 && "vor " + Math.ceil(day_diff / 30) + " Monaten" ||
"vor " + Math.ceil(day_diff / 365.25) + " Jahren";
}, },
heading: function() { heading: function() {