Change friendly time format

How would I change the "posted 1234 Days ago", to "posted on Dec 20, 2011" on Elgg 1.8? Thanks

  • I know lol a code I'm not, I'll read it word for word and see what I come uP with

  • Weelll - that PHP manual page does have sample code for the date/time function calls and what you coded above ?! lolz -- better read thru to check yr syntax lolz ;-) then u can laugh too when you see yr code 'typos'; not telling b/c the you can retain/have yr joy of 'discovery'.

  • I honestly tried hard, for a few hours, I got it display something depending on 24 hours ago, but am not sure how to make it display something if posted todau or yesturday, and how to get it to display the time only and not the date. I keep getting yelled at by the wife for speding so much time on the computer lol.

  • @Chris: your function says the following:

    if(){

    Today...

    }else{

    Yesterday...

    }else{

    ...

    }

    else cannot follow else. if(){}else{}......or.....if(){}elseif(){}else{}

    keep trying mate, you'll get there. 

    EDIT: you can repeat the elseif() call as many times as you like, (although there are better ways if you have loads of options)

    Also...your function seems to be missing the final "}", maybe you didn't put all the code in your post above.

    2ndEDIT: Try the following:

    function friendlytime_hook_handler($hook, $type, $return, $params) {

    if($params['time'] > (time() - (60*60*24))){

    return "Today at" . date("D, d M Y H:i");

    }else{

    return "Yesterday at" . date("D, d M Y H:i");

    }else{

    $old_time = $params['time'];

    $mdy = date("M j, Y", $old_time);

    $hm = date("g:ia", $old_time);

    $new_time_readable = elgg_echo('friendly_time', array($mdy, $hm));

    return $new_time_readable;

    }

    }

     

  • ok, here is what I came up with, it's ugly as hell but it works, the only small problem I'm having is it doesn't say "Yesturday" as of anytime before Midnight, for example, someone posted something on the site at 3:41pm yesturday and the site says post "Today" because it fals within the previous 24 hours, is there a way to fix this so it reads anytime before midnight as "Yeturday" and anything following Midnight as "Today"? thanks. ill post my start.php so you guys can see my mess, it does work however so I'm kinda proud.

    <?php

    elgg_register_event_handler('init', 'system', 'friendlytime_init');

    function friendlytime_init() {

    elgg_register_plugin_hook_handler('format', 'friendly:time', 'friendlytime_hook_handler');

    }

    function friendlytime_hook_handler($hook, $type, $return, $params) {
     
    if($params['time'] > (time() - (60*60*24))){
      
    $old_time = $params['time'];

    $hm = date("g:ia", $old_time);

    $today = elgg_echo('friendly_time_today', array($hm));

    return $today;

        return $today;

      } else if($params['time'] > (time() - (60*60*48))){

    $old_time = $params['time'];

    $hm = date("g:ia", $old_time);

    $yesturday = elgg_echo('friendly_time_yesturday', array($hm));

    return $yesturday;

        return $yesturday; }


    $old_time = $params['time'];

    $mdy = date("M j, Y", $old_time);
    $hm = date("g:ia", $old_time);

    $new_time_readable = elgg_echo('friendly_time', array($mdy, $hm));

    return $new_time_readable;

    }




     

  • Because this thread is getting really long for what should be a simple tweak:

    http://community.elgg.org/pg/plugins/project/833432/developer/Beck24/flexible-friendlytime-18x

     

    Please feel free to check out that little "Donations" button at the top left...

Feedback and Planning

Feedback and Planning

Discussions about the past, present, and future of Elgg and this community site.