Topic: Alternative format_time
i've just been messing with format_time and i've made a slightly different format for dates that happened today
so that instead of it being "Today Time" its "Today timesinceevent" e.g. "Today, 23 min, 25 sec ago"
//
// Format a time string according to $time_format and timezones
//
function format_time($timestamp, $date_only = false)
{
global $pun_config, $lang_common, $pun_user;
if ($timestamp == '')
return $lang_common['Never'];
$diff = ($pun_user['timezone'] - $pun_config['o_server_timezone']) * 3600;
$timestamp += $diff;
$now = time();
$date = date($pun_config['o_date_format'], $timestamp);
$today = date($pun_config['o_date_format'], $now+$diff);
$yesterday = date($pun_config['o_date_format'], $now+$diff-86400);
if ($date == $today)
$date = $lang_common['Today'];
else if ($date == $yesterday)
$date = $lang_common['Yesterday'];
if (!$date_only)
if ($date == $lang_common['Today'])
{
$diff = time() - $timestamp;
$rest = ($diff % 3600);
$hours = ($diff - $rest) / 3600;
$seconds = ($rest % 60);
$minutes = ($rest - $seconds) / 60;
if($hours > 1)
return $date.", $hours hours, $minutes min ago";
elseif ($hours == 1)
return $date.", an hour, $minutes min ago";
elseif ($hours == 0)
return $date.", $minutes min, $seconds sec ago";
}
else
return $date.' '.date($pun_config['o_time_format'], $timestamp);
else
return $date;
}
if its more than one hour it cuts off seconds