Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Show date instead of "Hours ago" etc

jrossjross New
edited April 2007 in Vanilla 1.0 Help
I would really like to post the date and time next to a post instead of showing 12 hours ago - or 5 seconds ago or minutes ago. Any easy solution for this?
«1

Comments

  • alter the function that renders the "1hour ago", package it in an extension, voila!
  • sounds like that answer is a solution to everything - thanks. lol
  • I'd be interested in an extension that allows you to configure how the post date is shown. If you're creating it jross, please be sure to shout about it when you release it :)
  • Well, I was hoping for some help myself instead of the generic answer that Adrian gave. I would alter the function and make an extension if I knew how.
  • edited January 2007
    There are 2 ways of achieving it. Since i dont know any possible negative consequences of doing it the second way, I'd do it the first way for safety.
    1) Theme change:
    Open up themes\comments.php and locate line 94: <span>'.$this->Context->GetDefinition('CommentTime').'</span>'.TimeDiff($this->Context, $Comment->DateCreated); Change it to: <span>'.$this->Context->GetDefinition('CommentTime').'</span>'.date(XYZ, $Comment->DateCreated);
    where XYZ is the format you want to view the time/date in, based on php.net's date function guidelines. Once you have made this change, save the new file to themes\vanilla

    OR

    2) Change the TimeDiff function in Framework.Functions.php. This could be done as an extension (I believe) using the object factory. Working out how to do it would take me some time (though it shouldnt be particularly complex) and as I dont know if it could have any adverse affects I wont go into it here now. If someone wants me to I'll take a look though.
  • 2) please mini :) With a pretty little box that admin's can dump their own PHP date function into :)
  • I meant I'd have a look at what was required to do it, not actually do it :P If you make the admin interface I'll make the back end.
  • You can't change it with an extension, I'm afraid, mini. It's a seperate function without any delegates, so you'd have to go in manually. It'd be pretty easy to do, though; you'd just need to delete (or comment out) what's already there then put in something like return date('H:i:s Y-m-d', $Time);(or however you want the date to look)
  • Can we have a delegate to change this then please?
  • Well looking at the current delegate/hook implementation, I'm not sure you can have a delegate for a single function, as it's based off the Delegation class.
  • The "'H:i:s Y-m-d" part is already changable, it's part of the language definition, so you don't need to change that in the core. It's called OldPostFormat or something like that.
  • I thought you could replace entire functions using the object factory, sirnot?
  • nope, you can only do that with classes, as instances of classes are variables which can be reassigned. you can't change a function natively in php, but apparently if you have the apd package there is a function called override_function, which would allow you to, well, override another function.
  • I see...fair enough then. As you say, it's hardly a hugely complex change to make.
  • ok guys, your thinking too much, y not just use a simple str_replace() function?

    here's something i quickly made up but i'm going fix it up a bit so i claim rights to finishing this extension :P

    <?php /* Extension Name: Date Settings Extension Url: http://lussumo.com/addons/ Description: Configurable Date Settings Version: 1.0 Author: Chris Vincent Author Url: http://ourpaintbox.com */ if($Context->SelfUrl == "index.php") { function TimeChooser(&$DiscussionGrid) { $TimeFormat = 'H:i:s Y-m-d'; $DiscussionClass = $DiscussionGrid->DelegateParameters['Discussion']; $DiscussionGrid->DelegateParameters['DiscussionList'] = str_replace( TimeDiff($DiscussionGrid->Context, $DiscussionClass->DateLastActive,mktime()), date($TimeFormat, $DiscussionClass->DateLastActive), $DiscussionGrid->DelegateParameters['DiscussionList']); } $Context->AddToDelegate("DiscussionGrid", "PostDiscussionOptionsRender", "TimeChooser"); } ?>
  • interesting...
  • It's definitely not very efficient, especially considering the date format isn't really going to be a very dynamic setting, but if you'd really rather have it as an extension...
  • Thanks Vincent, that's a great temporary fix, but I'd rather have a method that's done "The Right Way"(TM). So how can we do it the right way?
  • doesn't redeclaring a function, just overwrite the original function?
  • I honestly don't see what this fuss is all about, to reduce functionality.

    Surely if it says "minutes ago" or "hours ago" the date is obviously today and "one day ago" is obviously yesterday?

    It's a nice touch, relative dates is a cool thing to have and works well as long as you know what day it is.

    I guess I'm just used to it, the Mac Finder has had this as an option for years.

    Posted: Friday, 12 January 2007 at 11:21AM (AEDT)

This discussion has been closed.