Timezone / HourOffset problem

BleistivtBleistivt Moderator
edited June 2014 in Vanilla 2.0 - 2.8

My vanilla forum (running 2.1) is based in germany, so all times should be GMT+1 (EST) or GMT+2 (CEST) when it's daylight saving time.

I noticed, that GMT+0 times where shown for logged out users, so I changed the default timezone in bootstrap.php

date_default_timezone_set('Europe/Berlin');

(I would like to keep it that way, as this also fixed numerous problems with plugins showing the wrong time and the smarty time functions.)

Now, for logged out users, times are correct, but for users that are logged in, 2 hours are being added to the time, so GMT+4 times are shown.

Setting the the HourOffset in the Database to 0 for everyone will not work, as it is set back to 2 by global.js:

   var d = new Date()
   var hourOffset = -Math.round(d.getTimezoneOffset() / 60);

   // Set the ClientHour if there is an input looking for it.
   $('input:hidden[name$=HourOffset]').livequery(function() {
      $(this).val(hourOffset);
   });

see https://github.com/vanilla/vanilla/blob/ee5f4dd1d1d57e025bae5ca4806a99fc90b69675/js/global.js#L1138

Date().getTimezoneOffset() calculates the offset in minutes to UTC/GMT time.

I could just comment this out, but I think this is a bug in Vanilla as the Hour Offset calculation should use the server time and not UTC/GMT.

Is there any way I could change this, so the HourOffset calculation uses the server time?

Comments

  • peregrineperegrine MVP
    edited June 2014

    couldn't you just add the difference between your server time and utc time to the hour offset.

    either +2 or -2 not sure what you should be.

    // var  offsetServer=  2;
     var  offsetServer= -2;
         var d = new Date()
        var hourOffset = -Math.round(d.getTimezoneOffset() / 60) +offsetServer;
    

    the js by the way is performed on your client not on your server.

    you would need to get the timezone of your server from php and make js get it from the php routine with ajax or something else, if you wanted it automated.

  • BleistivtBleistivt Moderator

    Sure, but I would have to change that everytime its daylight saving time and changing the core files to show the correct local time seems wrong.

    My question was actually more in the way of: "Is the server time available in vanilla js and if not, how could I inject it to make this work?"

    Sorry if i was unclear.

  • LincLinc Admin

    Don't hack bootstrap.php. The config setting is Garden.GuestTimeZone.

  • BleistivtBleistivt Moderator

    Thank you, that did the trick! Didn't know of that config setting.

  • LincLinc Admin

    Sure thing :)

  • Is there an easy way to change timezone?

    As I understand, vanilla is pulling my server's time is that correct? The problem is that the server is in USA but website directed to latin america users, so I need to correct the timezone.

    Thanks!

  • BleistivtBleistivt Moderator
    edited November 2014

    No, latin american users that are logged in should see their timezone correctly.

    Vanilla sets the internal time to UTC and then adjusts the time shown to logged in users to match their computer clock.

    Guests will see UTC though, so you would add this config value:

    $Configuration['Garden']['GuestTimeZone'] = "America/Argentina/Buenos_Aires";
    

    You can find a list of valid values here:
    http://php.net/manual/en/timezones.php

Sign In or Register to comment.