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.

Confused about timezones ...

My forum is showing times one hour ahead of what they should be (ie, a discussion posted at 10.31 shows as 11.31).

Dates and times being formatted for output have an offset applied. the difference between UTC and the user's timezone (or the guest tz specified in config if not logged in). In other words, it is assumed that the date/times stored in the database are in UTC.

However, the date/times being written to the database are in fact in local time, not UTC. (function Gdn_Format->ToDateTime() uses PHP date() not gmdate()).

Am I missing something here?

(v2.6.3)

Comments

  • I still don't understand how this is supposed to work, unless it is assumed that Vanilla will only ever run on servers with a local time set to UTC. That isn't the case on my current shared hosting server (in the UK), and wasn't on the other shared hosting servers I have used in the past (located in Germany and the USA) -- all have used the local time of the server's location.

    Anyway, I have fixed it by adding date_default_timezone_set('UTC'); to the top of class.format.php.

    Unfortunately this is another core file change that will need reapplying on every upgrade.

  • There are a lot of discussions about time zones here. This is just one of them, but it holds a lot of information: https://open.vanillaforums.com/discussion/27669/time-zones

    Setting the default timme zone should normally be done on the server side by using the php.ini. If you cannot do that you can put your code in /conf/bootstrap.before.php (most probably you will have to create that file)

  • A few bits of info you may find helpful:

    • Vanilla operates in UTC.
    • We already set date_default_timezone_set('UTC'); in environment.php (which runs at the start of every request) so I'm wondering if you're really using 2.6 and why setting it a second time in a class file makes a difference.
    • Generally, if I'm recalling correctly, we do time conversions during the MySQL connection. Note that MySQL can exist on its own timezone separate from the server.
    • Being 1 hour off usually indicates a daylight saving time issue.
  • rgprgp New
    edited October 2018

    Thanks both, @Linc and @R_J -- I'm feeling really stupid now. =)

    I have a custom theme that integrates my forum into a wider website, and I now realise that as part of that a bit of shared code gets included that has date_default_timezone_set('Europe/London'); in it ...

    I do need that line for the wider site, but will change it to only execute it if it's not running in the forum context.

    Anyway, I'm glad there's a simple explanation, and sorry for wasting your time ...

    Richard.

Sign In or Register to comment.