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.

show date & time for comments (except the same day) but still only show date in thread-overview

edited June 2012 in Vanilla 2.0 - 2.8

ok, i know it's a bit confusing and i'm starting to think i'm confusing myself more and more but i tried about thousands of possibilities now and i guess i'm losing track... :-P

so what i want is:

  • _in_ discussions:
    • for comments at the same day only show time (as usual)
    • for older comments show date **and** time ('%d %B - %R')
  • at discussion overview:
    • for discussions where last comment was at the same day only show time (as usual)
    • for discussions where last comment was earlier still only show date

i alredy tried many variatons of-date($Object->DateInserted, ('Y m d') == date($Now, ('Y m d')) and similar stuff in various files but nothing ever worked... is there a much easier solution which i just can't see or what am i doing wrong?

thanks for help in advance!

Best Answers

  • 422422 Developer MVP
    edited June 2012 Answer ✓

    Search for timeago

    Demo http://vanillaskins.com/response

    There was an error rendering this rich post.

  • peregrineperegrine MVP
    Answer ✓

    you could also take a look at the Unreadicon plugin

    and modify it to your needs.

    It will show you how to test for time difference and then you can reformat the time in a plugin or in the helper_functions.php file.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Answers

  • 422422 Developer MVP
    edited June 2012 Answer ✓

    Search for timeago

    Demo http://vanillaskins.com/response

    There was an error rendering this rich post.

  • that gives me 4 results:

    • 1. Display full timestamp -- _just how to change time format_
    • 2. & 3. "How did wikihow forum realize to show "minutes ago" and not date/time?" -- _still simple question of time-format_
    • 4. Change style based on time/date? -- _looks quite interesting but still quite complicated (with image-file and stuff), shouldn't this be possible in a less complicated way?_

    in the class.format-file it's quite easy to define, so it also should be in other files or what's my mistake in thoughts?

  • 422422 Developer MVP

    I dont understnd your question.

    You want to change Posted:9.24 am to Posted:4 minutes ago ?

    There was an error rendering this rich post.

  • no, not at all.

    i want to change "posted april 24" to "posted april 24 - 13:22h" but only in discussions and only if the comment is not from the same day... so i changed defaultdateformat to '%d %B - %R'... but then there's the problem that in the thread-overview the format is changed too of course (and that doesn't look good). so i have to add something that changes that again, but only for the thread-overview.

    the other version is that i only change the time format in the theme/view/discussion folder, but then i have to add something ("if-else" like mentioned in first posting) which because of an unknown reason doesn't work... so why does this not work:

    $Now = time();
    $posttime = Gdn_Format::Date($Object->DateInserted);

    if (date($posttime, 'Y m d') == date ($Now, 'Y m d'))

  • peregrineperegrine MVP
    Answer ✓

    you could also take a look at the Unreadicon plugin

    and modify it to your needs.

    It will show you how to test for time difference and then you can reformat the time in a plugin or in the helper_functions.php file.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • ok, thanks a lot for the idea, i took a short look at the code of the plugin now and it seems to contain some new ideas, will have a closer look at it soon... :-) (now i have to get some sleep cause it's 3am here)
    and i forgot to mention that, but i'm working in the helper-functions.php file most of the time...

  • 422422 Developer MVP

    Shouldnt be to difficult all that info is stored. Best of luck

    There was an error rendering this rich post.

  • if it was that easy for me i wouldn't still be here... i'm cunfused... i think i got pretty close but i have one more question:

    when
    $indate = date($Sender->EventArguments['Comment']->DateInserted);
    echoes: "2012-06-10 00:06:26"

    why
    $indate = date('Y m d', $Sender->EventArguments['Comment']->DateInserted);
    echoes "1970 01 01"

    ?!

  • 422422 Developer MVP
    edited June 2012

    Epoch. You more than likely need to define another var, then parse it like $MyCustomDateTime

    There was an error rendering this rich post.

  • edited June 2012

    finally i found a solution, i just used a little trick (i just cut the date-string)... so if anyone is interested, here's the code for the helper-functions.php file in the "discussion" folder:

    <.span class="DateCreated">

            <?php
            $indate = $Sender->EventArguments['Comment']->DateInserted;
            $subindate = substr($indate, 0, 10);
            $subyear = substr($indate, 0, 4);
            $toyear = date('Y');
            $todate = date('Y-m-d');
    
             if ($todate == $subindate) {
             echo Anchor(Gdn_Format::Date($Object->DateInserted), $Permalink, 'Permalink', array('name' => 'Item_'.($CurrentOffset+1), 'rel' => 'nofollow'));
            } else {
               if ($subyear == $toyear) {
            echo Anchor(Gdn_Format::Date($Object->DateInserted, ('%d %B / %R')), $Permalink, 'Permalink', array('name' => 'Item_'.($CurrentOffset+1), 'rel' => 'nofollow'));   
               } else {
                  echo Anchor(Gdn_Format::Date($Object->DateInserted, ('%B %Y')), $Permalink, 'Permalink', array('name' => 'Item_'.($CurrentOffset+1), 'rel' => 'nofollow'));   
               }
               
            }
            ?>
         </span>
    
Sign In or Register to comment.