Skip to content

Instantly share code, notes, and snippets.

@cdennington
Last active December 14, 2015 14:08
Show Gist options
  • Save cdennington/5098790 to your computer and use it in GitHub Desktop.
Save cdennington/5098790 to your computer and use it in GitHub Desktop.
Redmine issue update
//Set an Interval on the function to run every 10 secs
setInterval(function() {
//Get actual date
var date = new Date();
//console.log(date);
var reDate = /(\d+)\/(\d+)\/(\d+)/;
//Make comment date into actual date format
jQuery('a[title]').filter(function(){
var a = jQuery(this);
return a.attr('title').match(reDate);
}).each(function () {
var a = jQuery(this);
var d = new Date(a.attr('title').replace(reDate, "$3/$2/$1"));
//console.log(d, 'd');
var time_diff = date - d;
var secs = time_diff/1000;
var minutes = secs / 60;
var hours = (minutes / 60);
var days = hours / 24;
var month = days / 30;
var year = month / 12;
//console.log(date, 'date');
//Workout how many milli seconds in X
var minInMilli = 60 * 1000;
var hourInMilli = minInMilli * 60;
var dayInMilli = hourInMilli * 24;
var monthInMilli = dayInMilli * 30;
var yearInMilli = monthInMilli * 12;
if(time_diff<1000) {
a.text('less than 1 second');
}else if(time_diff<minInMilli) {
a.text('less than a minute');
}else if(time_diff<hourInMilli) {
if (parseInt(minutes) > 1) {
a.text(parseInt(minutes) + ' minutes');
}else{
a.text(parseInt(minutes) + ' minute');
}
}else if(time_diff<dayInMilli) {
if (parseInt(hours) > 1) {
a.text(parseInt(hours) + ' hours');
}else{
a.text(parseInt(hours) + ' hour');
}
}else if(time_diff<monthInMilli) {
if (parseInt(days) > 1) {
a.text(parseInt(days) + ' days');
}else{
a.text(parseInt(days) + ' day');
}
}else if(time_diff<yearInMilli) {
if (parseInt(month) > 1) {
a.text(parseInt(month) + ' months');
}else{
a.text(parseInt(month) + ' month');
}
}else {
if (parseInt(year) > 1) {
a.text(parseInt(year) + ' years');
}else{
a.text(parseInt(year) + ' year');
}
}
});
}, 30000);
//Open external links in new tab
jQuery(document).ready(function() {
jQuery('a.external').attr('target', '_blank');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment