UseBB Community

The official board for UseBB help and discussion

UseBB Community » 1.0 Discussion » Nicer $functions->time_past() ?

Nicer $functions->time_past() ?

Page: 1

Author Post
Member
Registered: Mar 2005
Posts: 92
Location: Rethymno, Crete, Greece
Isn't this a little bit nicer ?
//
// Generate a time past string
//
function time_past($timestamp, $until='') {

global $lang;

$seconds = ( ( is_int($until) ) ? $until : time() ) - $timestamp;

$times = array();
$sections = array(
'weeks' => 604800,
'days' => 86400,
'hours' => 3600,
'minutes' => 60,
'seconds' => 0 );

foreach( $sections as $what => $length ) {
if ( $seconds >= $length ) {
$times[$what] = ($length >0) ? floor($seconds / $length) : $length;
$seconds %= $length;
}
}

$sections = array();
foreach ( $times as $key => $val )
$sections[] = $val.' '.$lang[ucfirst($key)];

return array($times, join(', ', $sections));
}
_______________
Yep I know me,.. thats that guy ..
> Lets script :: The PtokaX Lua Board :: The PtokaX Script Database
Developer
Registered: Apr 2004
Posts: 2202
Location: Belgium
Thanks. I decided earlier not to accept external code but I guess I will make some exceptions. ;)

Implemented in 0.4.1.
_______________
--Dietrich (developer)
UseBB roadmap, dev mailing list & weblog
Developer
Registered: Apr 2004
Posts: 2202
Location: Belgium
Oh,
$sections = array(
'weeks' => 604800,
'days' => 86400,
'hours' => 3600,
'minutes' => 60,
'seconds' => 0
);

needed to be
$sections = array(
'weeks' => 604800,
'days' => 86400,
'hours' => 3600,
'minutes' => 60,
'seconds' => 1
);

or the seconds would stay at 0. ;)
_______________
--Dietrich (developer)
UseBB roadmap, dev mailing list & weblog
Member
Registered: Mar 2005
Posts: 92
Location: Rethymno, Crete, Greece
thx for accepting the contribution and killing that bug :)
_______________
Yep I know me,.. thats that guy ..
> Lets script :: The PtokaX Lua Board :: The PtokaX Script Database

Page: 1

UseBB Community » 1.0 Discussion » Nicer $functions->time_past() ?

UseBB Community is powered by UseBB 1 Forum Software