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't get TIME right on Vanilla forum

mpb101mpb101 New
edited June 2015 in Vanilla 2.0 - 2.8

Hi,

I installed Vanilla forum on this site http://estespark.me/forum/ 2-3 days ago, and I've spent over four hours now trying to figure out how to get the TIME right on the forum.

The forum is a 'local' forum for a small resort town in Colorado. So I'm trying to get the time set to the MOUNTAIN time zone for both guests and members.

HostGator made some changes for me, so now GUESTS see all posts timestamped with MOUNTAIN time.

But when you login, you see a different time, which was originally UTC.

Searching online, I found different posts saying to make changes to the bootstrap file, php.ini and global.js...

On the global.js file, when I changed the timeoffset from 60 to 360 (on line 30) of the global.js file in the js folder, that got me to PACIFIC time.

So now when you login, you see posts timestamped according to PACIFIC time, which wouldn't be bad, except that this is a local forum. So I really need to get it set to MOUNTAIN time.

As an example, there's a post dated May 31 that shows the correct time (Mountain time) of 3:41 am when you're NOT logged in. But as soon as you login, the timestamp on that post changes to 2:41 am.

Even if I change the 360 (above) to 300, it stays at PACIFIC time.

I've seen code for that global.js page that helps offset for Daylight Savings Time. But I'm afraid to mess with the code too much (since I'm not a coder), unless someone can tell me exactly what lines to replace with what.

Here's the code I have currently in the global.js file (lines 29-35):

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

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

THE ONLY CHANGE I MADE TO THE CODE ABOVE WAS CHANGING THE 60 TO 360.

Here's some other code related to time offset (in the same file) that I didn't change at all (lines 1163-1170):

// Ajax/Save the ClientHour if it is different from the value in the db.
var setHourOffset = parseInt(gdn.definition('SetHourOffset', hourOffset));
if (hourOffset !== setHourOffset) {
$.post(
gdn.url('/utility/sethouroffset.json'),
{ HourOffset: hourOffset, TransientKey: gdn.definition('TransientKey') }
);
}

Any help is appreciated - Thanks!

Mark

-

Comments

  • BleistivtBleistivt Moderator

    Welcome to the community!

    Don't change anything in the code. Revert all your changes and possibly also changes that your hoster made for you. (Better overwrite all your files with a fresh download of Vanilla.)

    Then add $Configuration['Garden']['GuestTimeZone'] = 'GMT'; to your conf/config.php, but replace GMT with whatever timezone you want for guests on your forum:
    http://php.net/manual/en/timezones.php

    All timestamps are saved in UTC. Users that are logged in will always see timestamps converted to the timezone they are in (based on their devices time).

  • mpb101mpb101 New
    edited June 2015

    Thanks Bleistivt!

    I saved the original bootstrap.php file over the changed one, and changed the 360 back to 60 in the global.js file, and added the code you gave me to the config.php file (changing GMT to MST -- for Mountain time).

    Then I did a test post and it showed my time on the timestamp when I was logged in and when I was logged out.

    So I think it's fixed. :)

    The only thing I'm wondering about is that after I saved over the files above, the post I did at 3:41 am this morning (May 31) CHANGED to May 30. It's not showing the time, since it's yesterday, but it's probably the original UTC time of 9:41 PM (5/30) that it showed when I posted it at 3:41 AM today (5/31).

    And it didn't change back to May 31 -- as I assumed it would -- after I added your code to the php.config file.

    Do you know why it wouldn't correct the timestamp on that post to show 3:41 AM today (5/31) when I actually made the post, or does it just hard-code or something like that after a certain amount of time?

  • BleistivtBleistivt Moderator

    If you (or your hoster) changed the PHP timezone in bootstrap.php or index.php to something other than UTC, all recorded timestamps will be faulty, because Vanilla uses UTC internally and expects all timestamps to be in UTC.

  • Moral of the story is to not trust a host to make smart modifications to anything they are merely hosting.

    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.

Sign In or Register to comment.