Last change
on this file since 28441 was
19773,
checked in by plg, 12 years ago
|
new plugin birthdate to calculate age of people on each photo
|
File size:
1.1 KB
|
Line | |
---|
1 | <?php |
---|
2 | defined('BIRTHDATE_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | function birthdate_compute_age($birthdate, $date_ref=null) |
---|
5 | { |
---|
6 | $birthdate_unixtime = strtotime($birthdate); |
---|
7 | |
---|
8 | if (!isset($date_ref)) |
---|
9 | { |
---|
10 | $date_ref_unixtime = time(); |
---|
11 | } |
---|
12 | else |
---|
13 | { |
---|
14 | $date_ref_unixtime = strtotime($date_ref); |
---|
15 | } |
---|
16 | |
---|
17 | $nb_seconds = $date_ref_unixtime - $birthdate_unixtime; |
---|
18 | |
---|
19 | if ($nb_seconds < 0) |
---|
20 | { |
---|
21 | return null; |
---|
22 | } |
---|
23 | |
---|
24 | $nb_years = $nb_seconds / (60*60*24*365.25); |
---|
25 | if ($nb_years >= 2) |
---|
26 | { |
---|
27 | return sprintf(l10n('%d years'), $nb_years); |
---|
28 | } |
---|
29 | |
---|
30 | $nb_months = $nb_seconds / (60*60*24*30.4); // average 30.4 days each month |
---|
31 | if ($nb_months >= 2) |
---|
32 | { |
---|
33 | return sprintf(l10n('%d months'), $nb_months); |
---|
34 | } |
---|
35 | |
---|
36 | $nb_days = $nb_seconds / (60*60*24); |
---|
37 | if ($nb_days >= 2) |
---|
38 | { |
---|
39 | return sprintf(l10n('%d days'), $nb_days); |
---|
40 | } |
---|
41 | |
---|
42 | $nb_hours = $nb_seconds / (60*60); |
---|
43 | if ($nb_hours >= 2) |
---|
44 | { |
---|
45 | return sprintf(l10n('%d hours'), $nb_hours); |
---|
46 | } |
---|
47 | |
---|
48 | $nb_minutes = $nb_seconds / 60; |
---|
49 | if ($nb_minutes >= 2) |
---|
50 | { |
---|
51 | return sprintf(l10n('%d minutes'), $nb_minutes); |
---|
52 | } |
---|
53 | |
---|
54 | return sprintf(l10n('%d seconds'), $nb_seconds); |
---|
55 | } |
---|
56 | ?> |
---|
Note: See
TracBrowser
for help on using the repository browser.