Not Solved Last Post: X Minute(s)/Hour(s) Ago
#21
Not Solved
Thanks. It works nicely.

The only two(2) things I had to change is:
1.
$result = "$ordermleft {$lang->df_ago}";
to
$result = "{$lang->df_ago} $ordermleft";
as Hebrew is an RTL language.
2.
"1 {$lang->minute}"
to
"{$lang->minute}"
as in Hebrew (and, if I remember correctly, also Arabic) you don't say the no. '1' if its only 1 minute (or day...).


Also thanks for the "at" modification in the code. It now looks easily readable.


Ori...
Of two equivalent theories or explanations, all other things being equal, the simpler one is to be preferred.
simplified translation of Occam's razor

[Image: 82pwtx]
Reply
#22
Not Solved
You're welcomeWink
ProPortal: A More Functional Portal.
Click here for detailed information.
Reply
#23
Not Solved
Would you mind if I re-did the code for myself for the modifications I suggested?
Reply
#24
Not Solved
Of course you canWink
ProPortal: A More Functional Portal.
Click here for detailed information.
Reply
#25
Not Solved
(2009-01-02, 12:01 AM)DragonFever Wrote: Of course you canWink
Cool. Since I'm only gonna' modify it for the modifications I suggested, mind if I post it when I'm done?
Reply
#26
Not Solved
Actually, I updated it with changes made within your suggestions Confused
ProPortal: A More Functional Portal.
Click here for detailed information.
Reply
#27
Not Solved
Ah, good job!Smile
Reply
#28
Not Solved
ThanksSmile
ProPortal: A More Functional Portal.
Click here for detailed information.
Reply
#29
Not Solved
Hi,
As I understood DragonFever, you don't have a problem changing your code (a bit). Here is my add value to it:
"in/function.php"
/**
 * Calculates how many minutes past since the given time.
 *
 * @param int The unix timestamp of the given time
 * @return string The formatted time
 */
function timeAgo($last)
{
    global $mybb, $mybbadmin, $lang;
    
    $timenow = TIME_NOW;
    $diff = $timenow - $last;
    
    if(!$offset && $offset != '0')
    {
        if($mybb->user['uid'] != 0 && array_key_exists("timezone", $mybb->user))
        {
            $offset = $mybb->user['timezone'];
            $dstcorrection = $mybb->user['dst'];
        }
        elseif(defined("IN_ADMINCP"))
        {
            $offset =  $mybbadmin['timezone'];
            $dstcorrection = $mybbadmin['dst'];
        }
        else
        {
            $offset = $mybb->settings['timezoneoffset'];
            $dstcorrection = $mybb->settings['dstcorrection'];
        }

        // If DST correction is enabled, add an additional hour to the timezone.
        if($dstcorrection == 1)
        {
            ++$offset;
            if(my_substr($offset, 0, 1) != "-")
            {
                $offset = "+".$offset;
            }
        }
    }

    if($offset == "-")
    {
        $offset = 0;
    }
        
    if($last < $timenow && $diff <= 46200)
    {
        $order = $timenow - $last;
        while($order >= 180){
            $order = $order-60;
            $ordermleft++;
        }
        while($ordermleft >= 60){
            $ordermleft = $ordermleft-60;
            $orderhleft++;
        }

        if($ordermleft == 0){
            $ordermleft = "";
		} else {
			$ordermleft = "$ordermleft {$lang->minutes}";
		}
        if($orderhleft == 0){
            $orderhleft = "";
        } elseif($orderhleft == 1) {
			if($ordermleft >= 1){
				$ordermleft = "$ordermleft";
			} else {
				$ordermleft = "";
			}
			if($ordermleft >= 1) {
				$orderhleft = "$orderhleft  {$lang->hour} {$lang->and} $ordermleft";
			} else {
				$orderhleft = "$orderhleft {$lang->hour} $ordermleft";
			}
        } else {
            $orderhleft = "{$lang->more_then}$orderhleft {$lang->hours}";
        }
        
        if(!$ordermleft || $ordermleft == 1){ $ordermleft = "$ordermleft {$lang->minute}"; }
        $actualtime = gmdate($mybb->settings['timeformat'], $last + ($offset * 3600));
        
        if($orderhleft)
        {
            $result = "<abbr title=\"$actualtime\">$orderhleft {$lang->df_ago}</abbr>";
        } else {
            $result = "<abbr title=\"$actualtime\">$ordermleft {$lang->df_ago}</abbr>";
        }
            
        return $result;
    } else {
        return gmdate($mybb->settings['timeformat'], $last + ($offset * 3600));
    }
}
you, also, need to add to "global.lang.php" at the bottom:
$l['more_then'] = "more then";

If you'll notice, at the bottom of the resulted code I added that if the time is more then an 1 hour, minutes are added and when the time is more then 2 hours, I added "more then" to the front of the no. of hours.
Please note that you probably have to change the place of '$ordermleft'/'$orderhleft' and the before/after text as this was change by me to deal with a RTL language.


Hope this helps someone,
Ori...
I think my changed code has a delayed prompt in it. It seems that ittakes from 1 minute to 2 minutes, more then 1 minute. this is true for all the times (minutes full behind, hours+minutes do so as well).
If you see whats wrong, please correct (or this is normal?).


Ori...
OK. A third change in the code that solve a problem that caused the word 'minute' to appear twice when its in front of the word 'hour'. BTW, my code also has the line:
if(!$ordermleft || $ordermleft == 1){ $ordermleft = "$ordermleft {$lang->minute}"; }
in the hours calculation, so it says "Hour and Minute" and not "1 Hour and 1 Minute", as it should in Hebrew - I removed it from the code attached here.


I did change the code so that it should work in a LTR language (like English) based forum.


Ori...
Of two equivalent theories or explanations, all other things being equal, the simpler one is to be preferred.
simplified translation of Occam's razor

[Image: 82pwtx]
Reply
#30
Not Solved
ok...this isnt working for me...
i folowed DragonFeverĀ“s first post and it didnt work
i did excatly like he wrotte, i tryed many times....
the error i got are just some stupid codes and it says error on functions_forumlist on line 198. I checked the line 198 and its like DragonFever wrotte.
Any suggestions?Please help!
thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)