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.

Can users have personalized date / time format?

I searched a bit the forum, but only saw messages about adding locales to a Vanilla installation.

When I use phpBB, one feature I appreciate is the capability to:

  • set the date / time format in the strftime style. Not super intuitive, but handy.
  • set a timezone.
    So I can see the date / time at my local time (I posted at 17:58, wall clock, not at 21:58, server clock, which I don't care!); with my own preference of display (being French, I deeply dislike the AM/PM style... :-)).

Is it possible to have that in the user settings? Does a plugin already exist for that?

Comments

  • @PhiLho This isn't a user setting, no. I don't know if such a plugin exists.

  • I did some research on the topic in the past and, based on what I found, such feature could not be implemented easily in Vanilla 2.0.x. The reason is that, to format dates, Vanilla calls Gdn_Format::Date() method. Such method accepts a format as a parameter, and when that is not passed, it uses its own logic to determine the format (in short, it reads configuration and applies it). Unfortunately, the method doesn't fire any event, therefore the logic cannot be altered.

    Unless I missed something important, the only way I see to change the behaviour would be overriding the Gdn_Format class, which is not a recommended approach.

    Note about Vanilla 2.1b
    Class Gdn_Format is quite different in Vanilla 2.1b, and it implements a possible way to get around the above limitation. Method Gdn_Format::Date() checks for the existence of a global function named FormatDateCustom(). If such function exists, it calls it passing the timestamp to be formatted and the format to be used, and returns the result as is. This is probably an ad-interim solution, as relying on a global function is not an optimal approach (if such function is defined twice, the behaviour can be unpredictable), but it may be the only way to format dates and times on a per-user basis.

  • Too bad... :-(

    Forcing the same format for all users might be OK if users come from the same culture / country, but is a bit annoying for an international board.

    Thanks for the answers.

  • peregrineperegrine MVP
    edited September 2013

    @PhiLho said:
    Too bad... :-(

    Forcing the same format for all users might be OK if users come from the same culture / country, but is a bit annoying for an international board.

    Thanks for the answers.

    If it is that important to you, hack the core

    library/core/class.format.php

    add a country code to the user table and trigger off that
    to change the date formatting.

    for an example hack does something different but it wouldn't be too hard to implement what you want to do:

    http://vanillaforums.org/discussion/comment/171879/#Comment_171879

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

  • @peregrine said:
    If it is that important to you, hack the core
    library/core/class.format.php

    You can also create a plugin that contains a copy of such file, and it will override the core one (tested on Vanilla 2.0.x and 2.1b).

  • Do you know if it would be possible to just override one function by creating a file called class.format.php and defining only one function (the one to override) in it?

  • @R_J This file is a class which wouldn't be able to be declared twice. You can think of them a lot like view overrides, copy the entire thing and change what you need. The autoloader will prefer your custom file.

    If you were looking to override a specific function in any of the functions.*.php files, you will notice that they check for the function existing before defining themselves. This allows you to define any of these in your bootstrap-before file and have it "override" the core functionality.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • @R_J said:
    Do you know if it would be possible to just override one function by creating a file called class.format.php and defining only one function (the one to override) in it?

    No, that's not possible. In PHP, you cannot redeclare a class, nor override a single member of a class. There are some "hackish" ways to do it, but I would not recommend it.

  • I should have learned how to program before I've started coding :-D

  • @R_J said:
    I should have learned how to program before I've started coding :-D

    Where is the fun in that?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • peregrineperegrine MVP
    edited September 2013

    @businessdad said:
    You can also create a plugin that contains a copy of such file, and it will override the core one (tested on Vanilla 2.0.x and 2.1b).

    If I got some pledges and a bit of a spec of as to formats desired I would :).

    have you ever tried

    http://php.net/manual/en/book.runkit.php

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

  • Runkit is what I meant when I mentioned "hackish ways" of altering classes. I had a look at it, but I find it too dangerous to use, at the moment. Not to mention that it's an extension that might not be installed on the server where the code will be running, which would introduce another set of issues.

  • peregrineperegrine MVP
    edited September 2013

    I think the way I would do it, if I were writing a plugin would be just to just put a firevent in the appropriate spots in the core library/core/class.format.php and note it in the read me.

    one or two line addition and change instead of massive copying of file and class. Easier to upgrade that way.

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

  • edited September 2013

    Maybe this is a stupid question, but I was wondering , how is a flash clock able to detect the correct time no matter where you are ?

    I should take one apart to see what it has ....Adobe helped me find something ,

    http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f0e.html

  • @vrijvlinder said:
    Maybe this is a stupid question, but I was wondering , how is a flash clock able to detect the correct time no matter where you are ?

    Flash stuff is a real application running on your computer, and it has access to (almost) anything it wants. There is an article that describes how to determine the time zone using ActionScript, it doesn't seem difficult.

  • @peregrine said:
    I think the way I would do it, if I were writing a plugin would be just to just put a firevent in the appropriate spots in the core library/core/class.format.php and note it in the read me.

    one or two line addition and change instead of massive copying of file and class. Easier to upgrade that way.

    Somebody already thought about it. vQmod is used extensively by OpenCart, which doesn't implement a flexible plugin system and, therefore, it relies on core patches to allow modules to "inject" behaviour where needed. Flexible, powerful, but also delicate (patches may conflict with each other) and dangerous (changing core files as one wishes, even virtually, is always risky).

  • @businessdad said:
    Flash stuff is a real application running on your computer, and it has access to (almost) anything it wants.

    yes I understand that about flash, I tried to edit the comment to include that the ActionScript contains the meat of the time clock but was hit with a timeout error .

    May this be used elsewhere without the flash container ? Since we don't want to make it render a clock etc. Just use the determination of timezone...

    exactly !

Sign In or Register to comment.