aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authormistic100 <mistic@piwigo.org>2012-02-10 16:11:50 +0000
committermistic100 <mistic@piwigo.org>2012-02-10 16:11:50 +0000
commit69a704f13875cfbc1c090239d9d54d871f2ff8f7 (patch)
treeeee1c3722e95395b597a6ea01f905b9d7726411f /include
parentd0303b4ff06829e2d13f8134cbbb7b44f74d30b0 (diff)
feature 2564: forgot a file in previous commit
git-svn-id: http://piwigo.org/svn/trunk@13085 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/functions.inc.php63
1 files changed, 61 insertions, 2 deletions
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 691848326..925e43848 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -492,7 +492,7 @@ INSERT INTO '.HISTORY_TABLE.'
// The output is internationalized.
//
// format_date( "2003-09-15", true ) -> "Monday 15 September 2003 21:52"
-function format_date($date, $show_time = false)
+function format_date($date, $show_time = false, $show_day_name = true)
{
global $lang;
@@ -516,7 +516,7 @@ function format_date($date, $show_time = false)
$formated_date = '';
// before 1970, Microsoft Windows can't mktime
- if ($ymdhms[0] >= 1970)
+ if ($show_day_name and $ymdhms[0] >= 1970)
{
// we ask midday because Windows think it's prior to midnight with a
// zero and refuse to work
@@ -532,6 +532,65 @@ function format_date($date, $show_time = false)
return $formated_date;
}
+/**
+ * Works out the time since the entry post, takes a an argument in unix time or datetime
+ */
+function time_since($original, $stop = 'minute')
+{
+ if (!is_int($original))
+ {
+ $ymdhms = array();
+ $tok = strtok($original, '- :');
+ while ($tok !== false)
+ {
+ $ymdhms[] = $tok;
+ $tok = strtok('- :');
+ }
+ $original = mktime($ymdhms[3],$ymdhms[4],$ymdhms[5],$ymdhms[1],$ymdhms[2],$ymdhms[0]);
+ }
+
+ // array of time period chunks
+ $chunks = array(
+ array(60 * 60 * 24 * 365 , 'year'),
+ array(60 * 60 * 24 * 30 , 'month'),
+ array(60 * 60 * 24 * 7, 'week'),
+ array(60 * 60 * 24 , 'day'),
+ array(60 * 60 , 'hour'),
+ array(60 , 'minute'),
+ array(1 , 'second'),
+ );
+
+ $today = time(); /* Current unix time */
+ $since = abs($today - $original);
+
+ $print = null;
+ for ($i = 0, $j = count($chunks); $i < $j; $i++)
+ {
+ $seconds = $chunks[$i][0];
+ $name = $chunks[$i][1];
+ if (($count = floor($since / $seconds)) != 0)
+ {
+ $print.= ($count == 1) ? '1 '.l10n($name).' ' : $count.' '.l10n($name.'s').' ';
+ $since-= $count*$seconds;
+ }
+ if ($name == $stop)
+ {
+ break;
+ }
+ }
+
+ if ($today > $original)
+ {
+ $print = sprintf(l10n('%s ago'), $print);
+ }
+ else
+ {
+ $print = sprintf(l10n('%s in the future'), $print);
+ }
+
+ return $print;
+}
+
function pwg_debug( $string )
{
global $debug,$t2,$page;