MOD: Change Time and Date stamp from "y-m-d" to "1 hour 5 mins ago" MOD: Change Time and Date stamp from "y-m-d" to "1 hour 5 mins ago"
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

MOD: Change Time and Date stamp from "y-m-d" to "1 hour 5 mins ago"

Started by nickfzx, June 04, 2007, 11:21:08 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nickfzx

so this is what to do if you want to change coppermine to display dates and times as backward countdowns from the time of the event...e.g:

File Added 5 mins ago, comment made 2 days ago

instead of the current very regimental style of displaying the whole date and 24 hour clock.

you open functions.inc.php and replace the entire
function localised_date($timestamp = -1, $datefmt)
function

with this:
function localised_date($timestamp)
{

            $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, $minutes mins 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";

}


I have not tested it extensively but it seems to work ok...I will update if I find any problems with it.

Also not sure if I am supposed to release mods that involve editing core files...so apologies GauGau if this is a problem...I am only trying to contribute something.

Nibbler


nickfzx

no it doesn't, there is (was, I will edit out now) some punbb code left in there from my install

sorry for not seeing that :)


edit: now taken out the punbb code I had accidentally left in there

Fudgemaster

Thanks.

Works like a charm.

One modification I'd like to see tho..
In some point, like 1 months or so, it would switch back to showing the actual date..
So there wouldn't be a ton of "added 500 weeks ago" lines :)
--
It's an insane world.. But I'm proud to be a part of it.

nickfzx

yeah would be nice...i will do it at some point...I wanted to do it as "3 months ago" for example but you get the whole problem with the months having different numbers of days in them.

When I get round to the fix I'll post it here.