Timo ago wrong format for rtl

50 views Asked by At

This is a good code for Time Ago Returns: "now" or " 2 seconds ago ", etc

In rtl it returns wrong format like This image So I want to replace ago to become in the begins instead of the end How can i do it

if ( ! function_exists('time_ago'))
{
    function time_ago($datetime, $text = '') 
    {
        $full = false;

        $now = new DateTime;
        $ago = new DateTime($datetime);
        $diff = $now->diff($ago);

        $diff->w = floor($diff->d / 7);
        $diff->d -= $diff->w * 7;

        $string = array(
            'y' => lang('common_year'),
            'm' => lang('common_month'),
            'w' => lang('common_week'),
            'd' => lang('common_day'),
            'h' => lang('common_hour'),
            'i' => lang('common_minute'),
            's' => lang('common_second'),
        );
        
        foreach ($string as $k => &$v) 
        {
            if ($diff->$k) 
            {
                $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? '' : '');
            } 
            else 
            {
                unset($string[$k]);
            }
        }

        if (!$full) $string = array_slice($string, 0, 1);
        
        return strtolower($text).' '.($string ? implode(', ', $string) . ' '.lang('common_ago') : ' '.lang('common_now'));
    }

}
0

There are 0 answers