Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2012-10-08 14:28:01

orkneywd
Member
From: Orkney Islands, UK
Registered: 2008-05-10
Posts: 150

[Solved] Change 2012-09-28 02:09:18 to "5 days ago" etc?

I had this installed on Fluxbb 1.2 but can't find a similiar mod for Fluxbb 1.5. Has anyone done this already? I know the code that needs editing is includes/functions.php

function format_time($timestamp, $date_only = false, $date_format = null, $time_format = null, $time_only = false, $no_text = false)
{
	global $pun_config, $lang_common, $pun_user, $forum_date_formats, $forum_time_formats;

	if ($timestamp == '')
		return $lang_common['Never'];

	$diff = ($pun_user['timezone'] + $pun_user['dst']) * 3600;
	$timestamp += $diff;
	$now = time();

	if(is_null($date_format))
		$date_format = $forum_date_formats[$pun_user['date_format']];

	if(is_null($time_format))
		$time_format = $forum_time_formats[$pun_user['time_format']];

	$date = gmdate($date_format, $timestamp);
	$today = gmdate($date_format, $now+$diff);
	$yesterday = gmdate($date_format, $now+$diff-86400);

	if(!$no_text)
	{
		if ($date == $today)
			$date = $lang_common['Today'];
		else if ($date == $yesterday)
			$date = $lang_common['Yesterday'];
	}

	if ($date_only)
		return $date;
	else if ($time_only)
		return gmdate($time_format, $timestamp);
	else
		return $date.' '.gmdate($time_format, $timestamp);
}

The code I previously used in 1.2 was as follows:-

function format_time($timestamp, $date_only = false)
{
    global $pun_config, $lang_common, $pun_user;

    if (!$date_only)
        {
            $diff = time() - $timestamp;
            $rest = ($diff % 3600);
            $restdays = ($diff % 86400);
            $restweeks = ($diff % 604800);
            $weeks = ($diff - $restweeks) / 604800;
            $days = ($diff - $restdays) / 86400;
            $hours = ($diff - $rest) / 3600;
            $seconds = ($rest % 60);
            $minutes = ($rest - $seconds) / 60;
            if ($timestamp == '')
                return $lang_common['Never'];
            if($weeks > 1)
                return $date."$weeks weeks ago";
            elseif($days > 1)
                return $date."$days days ago";
            elseif($hours > 1)
                return $date."$hours hours ago";
            elseif ($hours == 1)
                return $date."1 hour ago";
            elseif ($minutes == 0)
                return $date."$seconds seconds ago";
            elseif ($minutes == 1)
                return $date."1 minute ago";
            elseif ($seconds < 60)
                return $date."$minutes mins ago";
        }
        else{
            $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);

            return $date;
           }
}

This code works on viewforum and viewtopic but not on the index?

edit: The reason the date wasn't showing on the index was because I'd already removed the timestamp from showing on the index lol

Last edited by orkneywd (2012-10-08 14:34:03)

Offline

#2 2012-10-08 16:44:12

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 5,857
Website

Re: [Solved] Change 2012-09-28 02:09:18 to "5 days ago" etc?

Cool. Do you want to package this up as a mod? smile


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#3 2012-10-08 21:33:13

hydn
Member
Registered: 2012-10-06
Posts: 22

Re: [Solved] Change 2012-09-28 02:09:18 to "5 days ago" etc?

so I can cut and paste this for my 1.5 install?

Any cons?

Last edited by hydn (2012-10-08 21:33:21)

Offline

#4 2012-10-09 11:11:20

unholy
Member
Registered: 2012-08-08
Posts: 12

Re: [Solved] Change 2012-09-28 02:09:18 to "5 days ago" etc?

Hi,

works for me !

Here is a french adaptation of the code:

function format_time($timestamp, $date_only = false)
{
    global $pun_config, $lang_common, $pun_user;

    if (!$date_only)
        {
            $diff = time() - $timestamp;
            $rest = ($diff % 3600);
            $restdays = ($diff % 86400);
            $restweeks = ($diff % 604800);
            $weeks = ($diff - $restweeks) / 604800;
            $days = ($diff - $restdays) / 86400;
            $hours = ($diff - $rest) / 3600;
            $seconds = ($rest % 60);
            $minutes = ($rest - $seconds) / 60;
            if ($timestamp == '')
                return $lang_common['Never'];
            if($weeks > 1)
                return $lang_common['x ago'].$date."$weeks ".$lang_common['weeks ago'];
                // "weeks ago";
            elseif($days > 1)
                return $lang_common['x ago'].$date."$days ".$lang_common['days ago'];
            elseif($hours > 1)
                return $lang_common['x ago'].$date."$hours ".$lang_common['hours ago'];
            elseif ($hours == 1)
                return $lang_common['x ago'].$date."1 ".$lang_common['hour ago'];
            elseif ($minutes == 0)
                return $lang_common['x ago'].$date."$seconds ".$lang_common['seconds ago'];
            elseif ($minutes == 1)
                return $lang_common['x ago'].$date."1 ".$lang_common['minute ago'];
            elseif ($seconds < 60)
                return $lang_common['x ago'].$date."$minutes ".$lang_common['minutes ago'];
        }
        else{
            $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);

            return $date;
           }
}

and add the following lines in lang/xx/common.php

for french:

// date
'x ago'         => 'Il y a ',
'weeks ago'     => 'semaines',
'days ago'      => 'jours',
'hours ago'     => 'heures',
'hour ago'      => 'heure',
'minutes ago'   => 'minutes',
'minute ago'    => 'minute',
'seconds ago'   => 'secondes',

and english

// date
'x ago'         => '',
'weeks ago'     => 'weeks ago',
'days ago'      => 'days ago',
'hours ago'     => 'hours ago',
'hour ago'      => 'hour ago',
'minutes ago'   => 'minutes ago',
'minute ago'    => 'minute',
'seconds ago'   => 'secondes ago',

Offline

#5 2012-10-11 01:55:00

orkneywd
Member
From: Orkney Islands, UK
Registered: 2008-05-10
Posts: 150

Re: [Solved] Change 2012-09-28 02:09:18 to "5 days ago" etc?

Franz wrote:

Cool. Do you want to package this up as a mod? smile

It wasn't my code originally so it's not really mine to package up. I did try looking for the original author but it was so long ago and I can't remember if I found it on punbb.org, fluxbb.org or punres.net hmm

Offline

#6 2012-10-11 10:54:46

Newman
Member
Registered: 2011-11-05
Posts: 343

Re: [Solved] Change 2012-09-28 02:09:18 to "5 days ago" etc?

function timeAgo($tm,$rcs = 1) {
    $cur_tm = time(); $dif = $cur_tm-$tm;
    $pds = array('second','minute','hour','day','week','month','year','decade');
        $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600);
    for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]);
 
    $no = floor($no); if($no <> 1) $pds[$v] .='s'; $x=sprintf("%d %s ",$no,$pds[$v]);
    if(($rcs > 0)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= timeAgo($_tm, --$rcs);
    return $x;
}

smile

Offline

Board footer

Powered by FluxBB 1.5.7