[Fusionforge-commits] r14773 - trunk/src/www/include

Alain Peyrat aljeux at fusionforge.org
Wed Nov 9 14:43:33 CET 2011


Author: aljeux
Date: 2011-11-09 14:43:32 +0100 (Wed, 09 Nov 2011)
New Revision: 14773

Modified:
   trunk/src/www/include/html.php
Log:
Add new relative_date() func to display nicer dates

Modified: trunk/src/www/include/html.php
===================================================================
--- trunk/src/www/include/html.php	2011-11-09 13:23:14 UTC (rev 14772)
+++ trunk/src/www/include/html.php	2011-11-09 13:43:32 UTC (rev 14773)
@@ -868,6 +868,29 @@
 	return $hashstr;
 }
 
+function relative_date ($date) {
+	$delta = time() - $date;
+	if ($delta<60)
+		return sprintf(ngettext('%d second ago', '%d seconds ago', $delta), $delta);
+
+	$delta = round($delta/60);
+	if ($delta<60)
+		return sprintf(ngettext('%d minute ago', '%d minutes ago', $delta), $delta);
+
+	$delta = round($delta/60);
+	if ($delta<24)
+		return sprintf(ngettext('%d hour ago', '%d hours ago', $delta), $delta);
+
+	$delta = round($delta/24);
+	if ($delta<7)
+		return sprintf(ngettext('%d day ago', '%d days ago', $delta), $delta);
+
+	$delta = round($delta/7);
+	if ($delta<4)
+		return sprintf(ngettext('%d week ago', '%d weeks ago', $delta), $delta);
+
+	return date(_('Y-m-d H:i'), $date);
+}
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"




More information about the Fusionforge-commits mailing list