Fork me on GitHub
Current release is 2.1.6 (21 Nov 2014).

Users who have not yet upgraded to 2.1 should get security release 2.0.18.14 (1 Nov 2014). We will stop providing these security releases to 2.0 at the end of this year.

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

edited June 2012 in Vanilla 2.0 Help

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

Answers

  • 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 ?

    422 Real Estate Australia , now open Check it out

  • 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'))

  • 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

    422 Real Estate Australia , now open Check it out

  • 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

    422 Real Estate Australia , now open Check it out

  • 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>
    
    422fh111
Sign In or Register to comment.