summaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
authorAlessandro Cosentino <cosenal@gmail.com>2012-11-06 10:56:42 -0500
committerAlessandro Cosentino <cosenal@gmail.com>2012-11-06 10:56:42 -0500
commit50dbb30eb9968cd328915c4632f2742e6e41ad66 (patch)
tree34228053763b4e5ba00fcffe8735d4211a3de467 /core/js
parent64ac208fb2e237f402af4bcaad8270086438061f (diff)
downloadnextcloud-server-50dbb30eb9968cd328915c4632f2742e6e41ad66.tar.gz
nextcloud-server-50dbb30eb9968cd328915c4632f2742e6e41ad66.zip
Moved relative_modified_date from file/js to core/js
Diffstat (limited to 'core/js')
-rw-r--r--core/js/js.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/core/js/js.js b/core/js/js.js
index 87d0a172082..2b2a64d25f9 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -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