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?

martzmartz New
edited January 2011 in Vanilla 2.0 - 2.8
On the they show a different time identifier than the default date/time notifier. How did they do that? I cannot find an addon for it.


  • martzmartz New
    edited January 2011
    I've been digging into this further and somehow think that this used to be how vanilla displayed time/date a long time ago (2006): . So maybe, it is quite easy to realize?

    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 ( ) 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!
  • edited January 2011
    Hey, martz.

    You are exactly right about the Gdn_Format::Date($Discussion->LastDate). That's the one.
  • edited January 2011

    Bonus: it changes in real-time. Also should help with the load a little (one function less to process)
  • thanks guys, really helpful!
  • oliverraduneroliverraduner Contributing to Vanilla since 2010 Switzerland ✭✭
    edited January 2011
    Good idea, @xatrix , but it's not possible using the jQuery plugin, because it requires the date value to appear like 2008-07-17T09:24:17Z or 2008-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"...
  • edited January 2011
    I'm sure it's possible. And I don't see why you'd need to overwrite a whole controller. What's wrong with overriding a function?

    In php, ISO 8601 timestamps are easy as date('c', $date).
  • I'm not sure what to do. Can this be made into an Addon?
  • oliverraduneroliverraduner Contributing to Vanilla since 2010 Switzerland ✭✭
    Sorry, didn't know you can overwrite functions in an addon... my fault @xatrix

    @jonathanbloom Yes, this could be achieved with a Plugin.
  • oliverraduneroliverraduner Contributing to Vanilla since 2010 Switzerland ✭✭
    edited January 2011
    @Mark You documented the possibility to override core functions, by "defining it before the framework does".

    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...

  • Vanilla already has the methods to do this. So Here it is:
    Create a theme and this is the discussions/helper_functions.php file

    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.
  • Can anyone help me? As in the original example, I would like to just show the date if a comment is more than seven days old.

    Thanks in advance!
  • Me too. As above.
Sign In or Register to comment.