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.

1969 Date issue in forums - how to solve?

edited April 2012 in Vanilla 2.0 - 2.8

Hello all,

I'm having an issue which I see has happened to others also, in that my users (or myself) see dates as Dec 1969 sometimes. However, it seems that signing out and back in again will temporarily fix this issue? Also, I noted that the hour is often 2 hours behind, but again seems to be corrected on signing out and back in again.

I've read up as much as I can on this issue, and have followed through with solutions suggested in other threads, including adding the following to my config.php file.

ini_set('date.timezone', 'Pacific/Auckland'); date_default_timezone_set("Pacific/Auckland");

Still no fix for this issue, unfortunately.

Does anyone have any new information on this? It's late tonight, and I know this isn't the most descriptive post ever - I'll try to come back and be more specific, but wanted to just throw the question out there in the hope that somebody might have discovered a solution for this. It's super frustrating, as I can't be continually explaining to users that it's ok, and nothing is broken etc.

I'm running PHP 5.2.9, Vanilla 2.0.18.2 and I checked phpinfo and my default timezone is America/New_York

Thanks so much for reading! :)

Tagged:

Best Answers

  • peregrineperegrine MVP
    edited April 2012 Answer ✓

    check the hour offset in your user table in vanilla. Each user gets an hour offset assigned (I believe the first time they log in - try changing it to 0, if it isn't already.
    You could assign different users -1 -2 -3 to see if any user gets the correct time when they login

    are you in the same timezone as your server?

    You want the timezone on your server to reflect the timezone where it resides

    I would remove anything that refers to Auckland everywhere - if your server is not in Auckland but is in NY.

    for ini_set and anywhere it is defined (config.php) it should be America/New_York
    if your server is in NY.

    It is saying 1969 because you are basing a 1970 time in NY based on auckland.

    you could also echo the timezone I believe it is

    echo getenv(TZ);

    you could test the same way you specified.

    From what you say it is working in SQL, and PHP normally. It is just within vanilla where the problem is.

    You could also view the cookies to see what date they are. Also is the time set correctly on your local computer and the server.

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

  • peregrineperegrine MVP
    edited April 2012 Answer ✓

    @WCNZ - This may help you - It will do the job any way.

    It will display the local time you set on discussion and discussion times for users who are not logged in.

    Don't worry it does not do any writing to the database, it purely modifies the times displayed on the fly.

    the plug in reads this statement that you manually add to your config.php
    You should be somewhere between 16 and 19 hours from NYC. Change the 19 to whatever you need.

    $Configuration['Plugins']['TimeZoneAdjust']['Hour_Offset'] = '19';

    I wrote it just to see if it would solve your problem. In any event you can get some ideas how to modify the helper_functions.php files to solve your problem.

    http://vanillaforums.org/addon/timezoneadjust-plugin

    let the like button know if you like it :).

    The plugin can be modified to adjust the time permalink to the new time if you want to do build the anchor and add one more line to the javascript.

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

«1

Answers

  • 422422 Developer MVP
    edited April 2012


    $time = strtotime($inputDate);
    $date = ($time === false) ? '0000-00-00 00:00:00' : date('Y-m-d H:i:s', $time);

    There was an error rendering this rich post.

  • 422422 Developer MVP

    Or


    date('Y/m/d', strtotime($date));

    There was an error rendering this rich post.

  • peregrineperegrine MVP
    edited April 2012

    The time displayed is based on the logged in users timezone. this is stored in vanilla.
    when they are logged out, it will not use the users timezone, but I believe the timezone of the server location. That is why you see different times logging in and out. As far as 1969 check the database and look up the specified date and time for the message you are looking at and see what that actual time. Generally the base time is based on jan 1, 1970 - which is when the time stamp is all zero's.

    It's a bit confusing that you say you set your timezone to auckland, when it is in fact new york

    when you execute a php script with this - does it echo the correct date and time.
    echo date('Y-m-d H:i:s');

    also check out PECL timezonedb module - maybe it isn't installed correctly.

    you could add this possibly to your scripts

    <?php
    define('TIMEZONE', 'America/New_York');
    date_default_timezone_set(TIMEZONE);
    

    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 April 2012

    @422, @peregrine Thank you both for your help! :)

    422, where should I be trying out the code which you shared? In the /views/ files? Thanks for stopping by to assist.

    Peregrine, I tried echoing the date as you suggested, and if I do so from an empty php script in my vanilla folder that just contains that code, I get the New York time. But if I place that line within a Vanilla file - say, discussions.php from applications/vanilla/views (just for testing) then I get my correct time here. I was logged in when I tried that, but then logged out, cleared all cookies, cleared browser cache, disabled cookies and refreshed...and it still showed the correct time here.

    I checked the database, and the DateInserted, DateUpdated, DateLastComment fields were all the correct timestamp (that is, they showed like 2012-04-09 21:21:19 which was the correct time here, when my test post was made).

    THEN. :D Then...I reenabled cookies, signed in to the forum again, placed the code you shared for defining timezone (exactly as above), in the top of discussions.php, and refreshed. And now we're back to January 1970, as the post time again. If I change the timezone to Pacific/Auckland instead, and refresh, the post time shows 1:22am (it was actually 9:22pm my time) so that mystifies me...1:22am isn't even NY time then? NY time would have been 5:22am. Now...if I post another comment in the discussion (timezone at Pacific/Auckland now), the post time shows as December 1969.

    I'm off to attempt some form of testing, to figure exactly what's going on. This is getting crazier by the minute! :P

  • 422422 Developer MVP
    edited April 2012

    The issue is epoch.

    As far as i know, not sure where you should add the code, with regard to forums. Prior to php 5 , there were other issues. Will try n find a fix for you.

    Try adding it to top of default.master.php

    Remember to add php tags.

    Try in yourtheme views default.master.php

    There was an error rendering this rich post.

  • peregrineperegrine MVP
    edited April 2012 Answer ✓

    check the hour offset in your user table in vanilla. Each user gets an hour offset assigned (I believe the first time they log in - try changing it to 0, if it isn't already.
    You could assign different users -1 -2 -3 to see if any user gets the correct time when they login

    are you in the same timezone as your server?

    You want the timezone on your server to reflect the timezone where it resides

    I would remove anything that refers to Auckland everywhere - if your server is not in Auckland but is in NY.

    for ini_set and anywhere it is defined (config.php) it should be America/New_York
    if your server is in NY.

    It is saying 1969 because you are basing a 1970 time in NY based on auckland.

    you could also echo the timezone I believe it is

    echo getenv(TZ);

    you could test the same way you specified.

    From what you say it is working in SQL, and PHP normally. It is just within vanilla where the problem is.

    You could also view the cookies to see what date they are. Also is the time set correctly on your local computer and the server.

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

  • 422422 Developer MVP

    Thatwould just change GMT offset tho?

    His issue is strtotime isnt it?

    There was an error rendering this rich post.

  • peregrineperegrine MVP
    edited April 2012

    his offset appears to broken to. if he gets Auckland times. maybe the timezones get conflicted when the wrong timezone auckland is set in vanilla and the server timezone is another.

    the comment times are being retrieved in helper_functions.
    Gdn_Format::Date($Discussion->LastDate)
    
    so if 
    echo $Discussion->LastDate;
    is fine
    but this get corrupted it will fine-tune where to look.
    echo (Gdn_Format::Date($Discussion->LastDate));
    - could see how it is retrieved from sql  and how it is converted
    

    also

     $today = getdate();
    echo $today;
    

    a couple of questions @WCNZ

    do you run the server?
    what time zone is the server in?
    is the time set correctly on the server
    ntp working
    is the time set correctly on on your local computer?
    most importantly:
    what was the problem before you started modifying things?

    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 April 2012

    Thank you both for your input! I'm on the case now, working through your suggestions, and will post back when I have results from them.

    Just briefly, I've checked the hour offset in the Users table, and my own value was -370557. I've changed that back to 0, and made sure that any references to ini_set the timezone is set back to America/New_York. I'm in New Zealand, but the server is based in NY.

    I just posted a test comment in my forum, and it's 12:28pm here, and it shows as 7:28pm. NYC is actually 8:28pm right now, but with the time difference, I would have expected the post date to have shown 'April 9th" instead, maybe? (of course, it's the 10th here.) Hmm. Will be back when I've worked through your suggestions - really appreciate you both taking the time to help. :)

  • peregrineperegrine MVP
    edited April 2012

    Create a new user and check the offset in the user table. That theoretically is the one you want.
    the offset should be the difference between auckland time and nyc time for you.
    Then when you are logged in you will get the correct time. I wouldn't (me) worry that the time reflects nyc time if I am not logged in. It will never be correct for users in multiple timezones anyway. e.g if I am not logged into this forum the hours are way off.

    What the vanilla software should really do is get location of the user by ip and convert the time according when not logged in, if there is no other wat to get a users local time if they are not logged in I would think. But that might cause some processing time. You could always build it in.

    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 New user created, offset was 0 in the DB. When I log in with those new credentials everything is perfect, with regards to time. :)

    The original problem, before I began editing anything, was that myself / users would see December 1969 as the date for new posts on the forum, and also in the admin control panel it would show certain users last login as December 1969. I searched around here and found that others had had the same problem. I couldn't be explaining to everyone that asked, that there was nothing really "wrong" and that the 1969 thing would go away (maybe) if they logged in / logged out / held their mouth the right way. ;)

    Other Q's: I don't run the server myself (I have access for development purposes). The server is in NY timezone, and I'm in Auckland timezone. The time on my local computer is definitely correct. :)

    With the creation of the new user, and the time working correctly etc. should we call this fixed? I've given up worrying that the time is NYC when the users are logged out. That's not such a biggie after all - just as long as it's not 1969 etc. If this is helpful to anyone else, or diagnosing a common problem, I can give you more info you'd like. Thanks again!

  • peregrineperegrine MVP
    edited April 2012

    glad it is solved. You could try adding the config statement with auckland but not the php.ini statements and see if that messes you up when you add a new user (and check the offset), if you wanted to play a little.

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

  • Righto! As soon as I switch back to Pacific/Auckland in config.php, all the dates of posts are switched back to December 1969. If I create a new user under that timezone scheme, their HourOffset is set to 0. Logging out and logging in as the new user gives a date of April 9th for all posts (true NY time I guess). Logging out that new user, then logging them right back in again gives them the correct time. I'll stick with the America/New_York timezone and people can deal with the odd hours issue. Compared to decades, it's not so bad!

    Thank you to both @peregrine and @422 for the time you spent helping / trying to trace this. I don't know exactly exactly what goes on with the issue, but as long as I can keep things within reasonable time, I'm happy. :) Cheers!

  • 422422 Developer MVP

    Your a kiwi.

    Its always beeraclock bro.

    There was an error rendering this rich post.

  • Busted! Always ginger-beer-oclock here. Bundaberg or bust...how's that for confused loyalties? ;)

  • 422422 Developer MVP

    BUNDY !!!! only comes in RUM flavour ;)

    There was an error rendering this rich post.

  • peregrineperegrine MVP
    edited April 2012 Answer ✓

    @WCNZ - This may help you - It will do the job any way.

    It will display the local time you set on discussion and discussion times for users who are not logged in.

    Don't worry it does not do any writing to the database, it purely modifies the times displayed on the fly.

    the plug in reads this statement that you manually add to your config.php
    You should be somewhere between 16 and 19 hours from NYC. Change the 19 to whatever you need.

    $Configuration['Plugins']['TimeZoneAdjust']['Hour_Offset'] = '19';

    I wrote it just to see if it would solve your problem. In any event you can get some ideas how to modify the helper_functions.php files to solve your problem.

    http://vanillaforums.org/addon/timezoneadjust-plugin

    let the like button know if you like it :).

    The plugin can be modified to adjust the time permalink to the new time if you want to do build the anchor and add one more line to the javascript.

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

  • peregrineperegrine MVP
    edited April 2012

    @WCNZ

    BTW, as a test I put in index.php just above the

    ini_set('date.timezone', 'Pacific/Niue'); 
    date_default_timezone_set("Pacific/Niue");
    

    which is an earlier time than my timezone. Just as NY is earlier than New Zealand - if you work in that frame of reference.

    and it worked fine withput the plugin. What you may have to do is change all your users to a 0 hour offset in the user table after you make the change, but it worked perfectly, when I wasn't logged in and when I was logged in.

        <?php
        define('APPLICATION', 'Vanilla');
        define('APPLICATION_VERSION', '2.0.18.3');
    
        // Report and track all errors.
        error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR);
        ini_set('display_errors', 'on');
        ini_set('track_errors', 1);
        ini_set('date.timezone', 'Pacific/Niue'); 
    date_default_timezone_set("Pacific/Niue");
    ob_start();
    

    It may be that you had multiple problems that were messing you up.
    But you could try the above with auckland time zone.

    without adding

    $Configuration['Plugins']['TimeZoneAdjust']['Hour_Offset'] = '19';

    Depending on your results - it might be worth deleting the plugin in the forum if the ini_set and date_default_timezone_set work.

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

  • If the above works for you. Then you could remove it from index.php
    and put it in your theme tpl file wrapped in 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.

  • @peregrine - WOW. Hey, thanks for being so helpful on this issue!! You've been simply fantastic. The plugin works like a charm, with a few little edits to tweak the date format to my preference, and get it working at category level, and post level. Should I post my small edits to it for others to use, or let them configure to their needs?

    With regards to your updates above (thank you!), I tested them out (with Auckland timezone) and disabled the plugin. After setting all the user hour offsets to 0, it gave me accurate NY time when logged out and also logged in. But not NZ time! :) I'm wondering if there are multiple things up with my install / server / settings, since I've had so much trouble with getting logical results.

    The plugin works really well in showing the NZ time for logged out users, and it seems that new users I create, get the correct time when logged in too. So in that way, everyone sees the right time, always. Super pleased - thank you! :)

Sign In or Register to comment.