Moved relative_modified_date from file/js to core/js

This commit is contained in:
Alessandro Cosentino 2012-11-06 10:56:42 -05:00
parent 64ac208fb2
commit 50dbb30eb9
2 changed files with 24 additions and 21 deletions

View File

@ -829,27 +829,6 @@ function getSelectedFiles(property){
return files;
}
function relative_modified_date(timestamp) {
var timediff = Math.round((new Date()).getTime() / 1000) - timestamp;
var diffminutes = Math.round(timediff/60);
var diffhours = Math.round(diffminutes/60);
var diffdays = Math.round(diffhours/24);
var diffmonths = Math.round(diffdays/31);
if(timediff < 60) { return t('files','seconds ago'); }
else if(timediff < 120) { return t('files','1 minute ago'); }
else if(timediff < 3600) { return t('files','{minutes} minutes ago',{minutes: diffminutes}); }
//else if($timediff < 7200) { return '1 hour ago'; }
//else if($timediff < 86400) { return $diffhours.' hours ago'; }
else if(timediff < 86400) { return t('files','today'); }
else if(timediff < 172800) { return t('files','yesterday'); }
else if(timediff < 2678400) { return t('files','{days} days ago',{days: diffdays}); }
else if(timediff < 5184000) { return t('files','last month'); }
//else if($timediff < 31556926) { return $diffmonths.' months ago'; }
else if(timediff < 31556926) { return t('files','months ago'); }
else if(timediff < 63113852) { return t('files','last year'); }
else { return t('files','years ago'); }
}
function getMimeIcon(mime, ready){
if(getMimeIcon.cache[mime]){
ready(getMimeIcon.cache[mime]);

View File

@ -675,6 +675,30 @@ function formatDate(date){
return $.datepicker.formatDate(datepickerFormatDate, date)+' '+date.getHours()+':'+((date.getMinutes()<10)?'0':'')+date.getMinutes();
}
/* takes an absolute timestamp and return a string with a human-friendly relative date
* @param int a Unix timestamp
*/
function relative_modified_date(timestamp) {
var timediff = Math.round((new Date()).getTime() / 1000) - timestamp;
var diffminutes = Math.round(timediff/60);
var diffhours = Math.round(diffminutes/60);
var diffdays = Math.round(diffhours/24);
var diffmonths = Math.round(diffdays/31);
if(timediff < 60) { return t('core','seconds ago'); }
else if(timediff < 120) { return t('core','1 minute ago'); }
else if(timediff < 3600) { return t('core','{minutes} minutes ago',{minutes: diffminutes}); }
//else if($timediff < 7200) { return '1 hour ago'; }
//else if($timediff < 86400) { return $diffhours.' hours ago'; }
else if(timediff < 86400) { return t('core','today'); }
else if(timediff < 172800) { return t('core','yesterday'); }
else if(timediff < 2678400) { return t('core','{days} days ago',{days: diffdays}); }
else if(timediff < 5184000) { return t('core','last month'); }
//else if($timediff < 31556926) { return $diffmonths.' months ago'; }
else if(timediff < 31556926) { return t('core','months ago'); }
else if(timediff < 63113852) { return t('core','last year'); }
else { return t('core','years ago'); }
}
/**
* get a variable by name
* @param string name