[ghelda-devel] [20] Add a function to compute the age. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/ghelda-devel Archives
]
Revision: 20
Author: odyx
Date: 2009-04-02 16:25:56 +0200 (Thu, 02 Apr 2009)
Log Message:
-----------
Add a function to compute the age.
Modified Paths:
--------------
trunk/inc/g_functions.php
Modified: trunk/inc/g_functions.php
===================================================================
--- trunk/inc/g_functions.php 2009-04-02 10:35:06 UTC (rev 19)
+++ trunk/inc/g_functions.php 2009-04-02 14:25:56 UTC (rev 20)
@@ -71,4 +71,27 @@
}
}
-?>
\ No newline at end of file
+function g_Age($date){
+ preg_match("`([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})`", $date, $regs);
+ $year_diff = date("Y") - $regs[1];
+ $month_diff = date("m") - $regs[2];
+ $day_diff = date("d") - $regs[3];
+ if ($month_diff < 0) {
+ $year_diff--;
+ $month_diff += 12;
+ }
+ elseif (($month_diff==0) && ($day_diff < 0)) {
+ $year_diff--;
+ $day_diff += 30; // TODO better...
+ }
+
+ $ret['years'] = $year_diff;
+ $ret['months'] = $month_diff;
+ $ret['days'] = $day_diff;
+ return $ret;
+}
+
+function g_AgeYears($date){
+ $rawArrayAge = g_Age($date);
+ return sprintf(T_('%d years old'),$rawArrayAge['years']);
+}