aboutsummaryrefslogtreecommitdiff
path: root/views/default/js/friendly_time.php
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2012-01-06 16:07:45 +0100
committerSem <sembrestels@riseup.net>2012-01-06 16:07:45 +0100
commit479e5b1bb819967665bb1933d268e16c16c69b70 (patch)
tree4e2a98cf72dfd72109f18263991d61cf407852c4 /views/default/js/friendly_time.php
parent9895df4280a7be9465fe148a356327edf370f6fa (diff)
downloadelgg-479e5b1bb819967665bb1933d268e16c16c69b70.tar.gz
elgg-479e5b1bb819967665bb1933d268e16c16c69b70.tar.bz2
Refactored javascripts. Added elgg.get_friendly_time() function.
Diffstat (limited to 'views/default/js/friendly_time.php')
-rw-r--r--views/default/js/friendly_time.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/views/default/js/friendly_time.php b/views/default/js/friendly_time.php
new file mode 100644
index 000000000..0b0275206
--- /dev/null
+++ b/views/default/js/friendly_time.php
@@ -0,0 +1,50 @@
+elgg.get_friendly_time = function(time) {
+
+ if (!time) {
+ time = new Date();
+ } else {
+ time = new Date(time);
+ }
+ diff = (new Date().getTime() - time.getTime()) / 1000;
+
+ minute = 60;
+ hour = minute * 60;
+ day = hour * 24;
+
+ if (diff < minute) {
+ return elgg.echo("friendlytime:justnow");
+ } else if (diff < hour) {
+ diff = Math.round(diff / minute);
+ if (diff == 0) {
+ diff = 1;
+ }
+
+ if (diff > 1) {
+ return elgg.echo("friendlytime:minutes", [diff]);
+ } else {
+ return elgg.echo("friendlytime:minutes:singular", [diff]);
+ }
+ } else if (diff < day) {
+ diff = Math.round(diff / hour);
+ if (diff == 0) {
+ diff = 1;
+ }
+
+ if (diff > 1) {
+ return elgg.echo("friendlytime:hours", [diff]);
+ } else {
+ return elgg.echo("friendlytime:hours:singular", [diff]);
+ }
+ } else {
+ diff = Math.round(diff / day);
+ if (diff == 0) {
+ diff = 1;
+ }
+
+ if (diff > 1) {
+ return elgg.echo("friendlytime:days", [diff]);
+ } else {
+ return elgg.echo("friendlytime:days:singular", [diff]);
+ }
+ }
+};