Template.messanging.helpers({
calculate_time_difference(a){
var dt = new Date(a);
var millis = new Date().getTime() - dt.getTime() ;
var minutes = Math.floor(millis / 60000);
var seconds = ((millis % 60000) / 1000).toFixed(0);
var hours = (millis / (1000 * 60 * 60)).toFixed(1);
var days = (millis / (1000 * 60 * 60 * 24)).toFixed(1);
if(minutes<1 && seconds<10){
return 'Just now';
}else if(minutes <1 && seconds<59 ){
return seconds + 'seconds ago';
} else if(minutes>= 1 && minutes<=59) {
return minutes + ' minutes ago';
}else if(minutes>59 && hours<24){
if(Math.floor(hours) ==1){
return Math.floor(hours) + ' hour ago';
}else{
return Math.floor(hours) + ' hours ago';
}
}else if(hours>24){
if(Math.floor(days) == 1){
return Math.floor(days) +" day ago";
}else{
return Math.floor(days) +" days ago";
}
}
else{
return minutes + ":" + (seconds < 10 ? '0' : '') + seconds + " [" + a.toString('YYYY-MM-dd').slice(0,25) + "] ";
}
},
Comments
Post a Comment