This format time for phpBB?
Posted January 21st 2017, 8:14pm
Hey, how can i use this format time for phpbb?
Demo:

Image

Simple time, and when i hover to display full format.. :D
φ
Posts: 9
Joined: January 19th 2017, 6:22pm
Likes Given: 5
1
#2
This format time for phpBB?
Posted January 22nd 2017, 11:17am
This would require edits to core files such as viewforum.php, viewtopic.php, and includes/functions_display.php. You would also need to edit your templates to include the additional information.

However, if you want a time display such as "Yesterday" or "5 hours ago", that would require a rewrite of the time formatting function in phpBB.

And finally, the only way to accomplish this is to disable the time display preference in the user control panel. That could make some of your members unhappy.

What I'm trying to say here is, I'm not sure this is a good idea. But if you really want to do it, I'll provide a couple code snippets to help you get started.
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
This format time for phpBB?
Posted January 22nd 2017, 11:32am
Yea man :D i want it, so cool and simple (to view i mean). :) And thx for the help!
φ
Posts: 9
Joined: January 19th 2017, 6:22pm
Likes Given: 5
This format time for phpBB?
Posted January 23rd 2017, 12:50am
If you want this, then you have a lot of work ahead of you. First, you're going to have to rewrite the format_date() function in the session.php file (user.php in phpBB 3.1+), and delete the timezone preference section from the ucp_prefs_personal.html template file.

At that point you can call the format_date() function twice whenever a date is needed in a template variable. For example, here is a line from the viewforum.php file:

	'FIRST_POST_TIME'			=> $user->format_date($row['topic_time'], true),

What you'll need are two lines, the first in the new relative format, and the second in absolute format. Here is an example of what those lines would look like:

	'FIRST_POST_TIME'			=> $user->format_date($row['topic_time'], true, true),
'FIRST_POST_TIME_ABS' => $user->format_date($row['topic_time'], false, true),

You could then use these values in the viewforum_body.html template to format dates exactly how you described.

This is a lot of work. Good luck!
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
This format time for phpBB?
Posted January 23rd 2017, 7:11pm
Later edit: i used this function:
function zdateRelative($date)
{
$now = time();
$diff = $now - $date;

if ($diff < 60){
return sprintf($diff > 1 ? '%s seconds ago' : 'a second ago', $diff);
}

$diff = floor($diff/60);

if ($diff < 60){
return sprintf($diff > 1 ? '%s minutes ago' : 'one minute ago', $diff);
}

$diff = floor($diff/60);

if ($diff < 24){
return sprintf($diff > 1 ? '%s hours ago' : 'an hour ago', $diff);
}

$diff = floor($diff/24);

if ($diff < 7){
return sprintf($diff > 1 ? '%s days ago' : 'yesterday', $diff);
}

if ($diff < 30)
{
$diff = floor($diff / 7);

return sprintf($diff > 1 ? '%s weeks ago' : 'one week ago', $diff);
}

$diff = floor($diff/30);

if ($diff < 12){
return sprintf($diff > 1 ? '%s months ago' : 'last month', $diff);
}

$diff = date('Y', $now) - date('Y', $date);

return sprintf($diff > 1 ? '%s years ago' : 'last year', $diff);
}


its a good idea to used it or to remove? I used like this in viewforum:
dream said:
<time title="{FIRST_POST_TIME}">{FIRST_POST_TIME_SIMPLE}</time>
φ
Posts: 9
Joined: January 19th 2017, 6:22pm
Likes Given: 5
This format time for phpBB?
Posted January 30th 2017, 8:19am
This is for 3.1, but maybe you could take a look on the code:
https://github.com/MuhClaren/timeago

It maybe can help.
φ
Posts: 14
Joined: November 16th 2015, 9:18am
Likes Given: 5

Who is online

Users browsing this forum: No registered users and 3 guests