File size: 682 Bytes
f5071ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
function timeSince(date) {
var seconds = Math.floor((new Date() - date) / 1000);
var interval = seconds / 31536000;
if (interval > 1) {
return Math.floor(interval) + " year ago";
}
interval = seconds / 2592000;
if (interval > 1) {
return Math.floor(interval) + " month ago";
}
interval = seconds / 86400;
if (interval > 1) {
return Math.floor(interval) + " day ago";
}
interval = seconds / 3600;
if (interval > 1) {
return Math.floor(interval) + " hour ago";
}
interval = seconds / 60;
if (interval > 1) {
return Math.floor(interval) + " minute ago";
}
return Math.floor(seconds) + " seconda ago";
}
export default timeSince;
|