Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
How did wikihow forum realize to show "minutes ago" and not date/time?
martz
New
On the http://forums.wikihow.com/ they show a different time identifier than the default date/time notifier. How did they do that? I cannot find an addon for it.
1
Comments
In the helper php there is this code: Gdn_Format::Date($Discussion->LastDate). if I copy this helper to my template folder and adjust it to use the code I found in this thread I think I will get it to work ( http://vanillaforums.org/discussion/511 ) it has this code:
function TimeDiff($Time, $TimeToCompare = "") {
if ($TimeToCompare == "") $TimeToCompare = time();
$Difference = $TimeToCompare-$Time;
$Days = floor($Difference/60/60/24);
$Difference -= $Days*60*60*24;
$Hours = floor($Difference/60/60);
$Difference -= $Hours*60*60;
$Minutes = floor($Difference/60);
$Difference -= $Minutes*60;
$Seconds = $Difference;
if ($Days > 7) {
return date("M jS Y", $Time);
} elseif ($Days > 0) {
return FormatPlural($Days, "day ago", "days ago");
} elseif ($Hours > 0) {
return FormatPlural($Hours, "hour ago", "hours ago");
} elseif ($Minutes > 0) {
return FormatPlural($Minutes, "minute ago", "minutes ago");
} else {
return FormatPlural($Seconds, "second ago", "seconds ago");
}
}
but I have a strong feeling that (as an inexperienced vanilla man) that there is a much better solution and would really appreciate if somebody could point me into the correct direction - thanks!
You are exactly right about the Gdn_Format::Date($Discussion->LastDate). That's the one.
Bonus: it changes in real-time. Also should help with the load a little (one function less to process)
2008-07-17T09:24:17Z
or2008-07-17
And with a Vanilla Plugin you cannot modify a single Date-Output-line (let's not talk about overwriting a whole controller only because of the date output ;-)).
Therefore I don't see a way to realize this. It would require an enhancement in the core, and with an according setting you could trigger Garden's Date-Function to return either "January 2011" or something like "X days ago"...
In php, ISO 8601 timestamps are easy as date('c', $date).
@jonathanbloom Yes, this could be achieved with a Plugin.
Could you please give me an example related to this discussion, how the function Gdn_Format::Date() {} could be replace by a custom Date() function in a plugin? I just don't get it :-) And unfortunately I did not found any example in other plugins...
Thanks!
Create a theme and this is the discussions/helper_functions.php file
http://pastie.org/1479072
Basically just added a method called TimeAgo which takes the time and works out the difference and uses vanillas built in method Seconds in the format class to do the rest.
Thanks in advance!