| 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; | |