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.
Options

Date is out by one day?

blizeHblizeH ✭✭
edited February 2010 in Vanilla 2.0 - 2.8
Hi guys,

Seem to have a small problem with the date on the forum - if you post something today, instead of letting you know when it was posted as a time, it just says 'February 6th' which of course was yesterday!

I'm guessing it's not a problem with the server time being out, as it almost seems like the comments are getting yesterdays date when being posted, but today's date is right when you're browsing the forum, if that makes sense :S

Any ideas what it could be please? I couldn't find any in the settings :(

Thanks

Comments

  • Options
    The server time is Canada time (and by default as well on new install).
    When you see the time of today's post, it is calculated via some javascript stuff that makes out your timezone, and shows the correct date for the post.
    For stuff that is yesterday (or before) for the server, time wise, I guess timing recalculation is done.

    If I remember it tomorrow, I will try to browse the code to find out exactly how it works.
  • Options
    Ah, thanks luc - I did notice the board was set to 'CA' but it was the only option in the drop down, d'oh! :-)
  • Options
    Sorry to bump this, but any ideas please? It's not so much that the date is out by a day that's causing problems (you can allow for that) but also you can never see what time each comment was posted, because it always has yesterdays date :(

    Cheers
  • Options
    You can change the way the date is displayed, get those parameters from config-default.php and put them in config.php and tweak them to your liking:
    $Configuration['Garden']['DefaultDateFormat'] = 'F j, Y';
    $Configuration['Garden']['DefaultDayFormat'] = 'F j';
    $Configuration['Garden']['DefaultYearFormat'] = 'F Y';
    $Configuration['Garden']['DefaultTimeFormat'] = 'g:ia';
  • Options
    Thanks luc - what would you recommend I change them to? :( Is there anyway to find the date somewhere and add one to the number of days? Sorry to be a pain
  • Options
    Whatever you like.
    Check php documentation. http://www.php.net/manual/en/function.date.php

    If you're running your own server, you could change the default timezone too.

    In bootstrap.php, you could change :
    date_default_timezone_set('Canada/Saskatchewan');

    I don't know where it should normally be set, as Garden tries to access it before (ini_get('date.timezone')), maybe php.ini
  • Options
    Many thanks for that luc - pretty cool solution!

    Is there *any* way to maybe make the date it stores the posts at as +1 day or something though? I only ask because for a few days of running Vanilla 2 it was fine, then suddenly the date went out. Also worth noting I have a Vanilla 1 installation on the very same server and the date is fine on that (and has been for around 3 years now!)
  • Options
    I suspect there's a command you could run to fix the posts, but it might not happen automatically as I don't know if MySQL stores timezone data, it probably just converts it into UTC. Anyway, yes, the time zone should match one of these: http://php.net/manual/en/timezones.php and you should have it set already in your php.ini file, look for "date.timezone". Only if it's not set will it use Canada/Saskatchewan or whatever. I would suggest setting it, if possible, so that all your hosted sites know the local time zone. (In fact, PHP 5.3+ will print a warning if neither date.timezone or date_default_timezone_set is set.)
  • Options
    Thanks Louis, am I right in thinking php.ini is something you can only view and edit on the actual server? I've just had a look on my FTP and can't see it anywhere :( Will contact my host on the off chance they could do something about it, cheers
  • Options
    Yep, it's server-side only. You can check its value (and see all kinds of stuff about your configuration) by running phpinfo(). Just search for "timezone" in your browser.
  • Options
    Thanks, it says...
    date/time support enabled
    "Olson" Timezone Database Version 2007.5
    Timezone Database internal
    Default timezone America/New_York
    I'm guessing they won't change it either, since the host is based in New York, boo! :(
  • Options
    edited February 2010
    Well, you could comment out the if statement for ini_get('date.timezone') in bootstrap.php, then change the date_default_timezone_set line to reflect the timezone you want: http://php.net/manual/en/timezones.php

    I think we've also identified a missing feature of Vanilla-- a timezone screen that shows the PHP timezone by default but allows overriding via a config param.
  • Options
    Cheers Louis, just changed it to this:
    // Make sure a default time zone is set
    /* if (ini_get('date.timezone') == '')
    date_default_timezone_set('Canada/Saskatchewan'); */
    date_default_timezone_set('Europe/London');
    Still the same unfortunately! :( It's weird because I wonder if the entire doubt was out, it wouldn't matter too much as it'd still show a date right?

    At the moment if I post something, it always shows yesterdays date, so it's like the date for storing the posts is different to the date that reads the posts? Will try disabling the add-ons we have quickly and see if it fixes itself :s
  • Options
    logout/log back in.
    The javascript for displaying date is processed then. (maybe it puts something in the cookie, don't know)
  • Options
    Umm! Logging back out and back in again works a treat - that's really strange... :(
  • Options
    MarkMark Vanilla Staff
    @luc @blizeH - When you sign out & in it uses javascript to get your timezone and saves it to your preferences in the user table. It uses this to figure out the diff from the server time and display the info for you correctly. Strange that you didn't have the appropriate time to begin with. But if you ever lose it, signing in and out always fixes the problem.
  • Options
    blizeHblizeH ✭✭
    edited February 2010
    Ahh excellent, thank you Mark! Nice to know that it's so easily fixed like that :) Many thanks to others for the help & suggestions too.
  • Options
    @Mark ah and that clarifies why you can't set the timezone in Vanilla. I wonder how it handles daylight-savings transitions, you might have to logout and back in again?
  • Options
    MarkMark Vanilla Staff
    Yes, you would. Todd was thinking about storing the users GMT offset, and I've been trying to think of an unobtrusive way to reset the value every once in a while...
  • Options
    Well, short of calculating DST in JS, I suppose you could just send along the value the server thinks is the current time for the user, and have JS on the browser check if that's correct. Only if it's not correct, then, would the browser ping the server saying so. If the entire forum were AJAX like Gmail, then I could see the browser's JavaScript storing the offset permanently and then checking occasionally against the browser's reported time to ensure it's correctness.

    How does Vanilla handle the time offset for those without JS? I can't remember right now ... but I imagine it just uses PHP's time zones, right? Would be awesome to use some kind of MaxMind/Geo IP product to locate where the IP address is, though I'm probably dreaming and it's overkill for just those without JS.
Sign In or Register to comment.