Welcome Guest, Not a member yet? Register   Sign In
timespan() shortening
#3

[eluser]ebot[/eluser]
you look at this i made my self and added the codes on the date help you can use it directly like how you use the codeigniter help ok. if anything feel free to contact me at ebot.tabi[at]gmail[dot]com:

here is the link this forum: http://ellislab.com/forums/viewthread/131489/
Code:
if ( ! function_exists('when'))
{
    function when($dt,$precision=2)

    {
    $times=array(    365*24*60*60    => "year",
                    30*24*60*60        => "month",
                    7*24*60*60        => "week",
                    24*60*60        => "day",
                    60*60            => "hour",
                    60                => "minute",
                    1                => "second");

    $passed=time()-$dt;

    if($passed<5)
    {
        $output='less than 5 seconds ago';
    }elseif($passed > 172800){
         $output=date("jS F,Y",$dt);
    }
    else
    {
        $output=array();
        $exit=0;

        foreach($times as $period=>$name)
        {
            if($exit>=$precision || ($exit>0 && $period<60)) break;

            $result = floor($passed/$period);
            if($result>0)
            {
                $output[]=$result.' '.$name.($result==1?'':'s');
                $passed-=$result*$period;
                $exit++;
            }
            else if($exit>0) $exit++;
        }

        $output=implode(', ',$output).' ago';
    }

    return $output;
}


Messages In This Thread
timespan() shortening - by El Forum - 01-15-2010, 07:05 PM
timespan() shortening - by El Forum - 01-16-2010, 06:00 AM
timespan() shortening - by El Forum - 01-16-2010, 01:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB