• so, I ad issues a few years ago with stuff in WordPress showing the wrong time. That was fixed, eventually — and settings were made across the board and on the server to set the php timezone to America/New York.

    Other scripts on my site need this setting to be correct.

    Now, I am noticing the issues starting again with WordPress.
    I found this, from last year
    https://www.ads-software.com/support/topic/utc-time-wrong/page/2/

    I set a quick check
    <?php
    date_default_timezone_set( ‘UTC’ );
    echo date(‘Y-m-d G:i:s’);
    and it correctly displays the UTC time as being 4 hours ahead of my local time.

    However, in WordPress General Settings (timezone set to New York)
    Universal time (UTC) is 2018-10-01 13:00:15. Local time is 2018-10-01 09:00:15.

    what is showing here is my correct time for UTC and an ADDITIONAL 4 hours then gets applied…. making all times 4 hours behind the actual time.

    you can see it here…
    https://www.chelmsforddogassociation.org/about-us/volunteering/
    the add-on is displaying times 4 hours ahead of the actual times… because I told it that the event starts at 9am EDT — so it displays 5am EDT.

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • If you are saying that WordPress is showing the correct time in Settings, and the post made by a plugin is showing the incorrect time, I would conclude that the plugin has the problem.

    If you created the post and then changed the time, it is still using the time saved when the post was created.

    Thread Starter kindred

    (@kindred)

    That’s my point… it’s very odd behavior.

    WordPress shows the WRONG values in the General Settings page.

    The post times themselves are correct.

    However, nearly every add-on is showing the servertime-4 (which ends up being utc-8) instead of UTC-4

    So, while I admit that I have not walked through every bit of code – since the setting is displaying wrong and every add-one which uses that setting is displaying wrong – the error is in the WordPress code, somewhere.

    The volunteer add-on is merely the one front-end display of times that I can easily link to…

    • This reply was modified 6 years, 2 months ago by kindred.

    I’m confused. You said that UTC is 4 hours ahead of your time, and

    However, in WordPress General Settings (timezone set to New York)
    Universal time (UTC) is 2018-10-01 13:00:15. Local time is 2018-10-01 09:00:15.

    shows that it is 4 hours ahead of your time. Yet, you say that

    WordPress shows the WRONG values in the General Settings page.

    When you choose a time zone in WordPress, you are not setting the time zone for the server, but for the dates saved in the database. It saves two times, actually. The server could be in a different time zone.

    Just curious, are you using a Windows server? It does time a little different than Linux. By the way, there is a ticket for attempting to get all the time stuff standardized. I haven’t seen anything about it in the last month or so, but there was some work done on it before that.

    If the plugins that you are using are getting the server time and mixing it with the WordPress time, it could be a mess. But plugins should use the WordPress time and be fine.

    The times in the General Settings page have always been off for me. In the PHP.INI file I set date.timezone = America/Chicago and I picked Chicago in the General Settings Dropdown. But, it shows ” Universal time (UTC) is 2018-10-02 00:53:32. Local time is 2018-10-01 19:53:32. ”

    Right now it is really 12:53 AM Central Time, locally. The UTC time should be 5:53 AM.

    Now, all of my posts and stuff show the correct times they were published and so on. I just think the time functions on this page are messed up.

    I think what’s happening is it assumes that PHP is set for UTC time and not Central Time. I should go look at the actual code and see what it’s doing. I seem to remember doing this before.

    • This reply was modified 6 years, 2 months ago by MarkRH.

    Well, I fixed my issue. It seems in my theme’s functions.php I had the following in it:
    date_default_timezone_set('America/Chicago');

    I commented that line out and now the General Settings shows:
    Universal time (UTC) is 2018-10-02 07:22:34. Local time is 2018-10-02 02:22:34.

    That matches what it should be.

    So, it’s possible something similar is causing it in your case. It doesn’t make sense that this would affect it though.

    Thread Starter kindred

    (@kindred)

    Thanks for the suggestion Mark – I looked through the theme files an was not able to find any timezone definition in any of them. ??

    Joy, the issue is not the 4 hour difference – the issue is the base time to which the 4 hour difference is applied.

    However, in WordPress General Settings (timezone set to New York)
    Universal time (UTC) is 2018-10-01 13:00:15. Local time is 2018-10-01 09:00:15.

    When I said this — local EDT time was 2018-10-01 13:00:15
    However, the WordPress settings were reading that as UTC and were then applying an ADDITIONAL 4 hour difference….
    So, WordPress is displaying UTC as UTC-4 instead of UTC-0 and the local time was displayed as UTC-8 instead of UTC-4

    … and no, my server is apache with php7

    As I said, the very strange thing about this is that
    1- the general settings shows incorrectly. (UTC-8)
    2- Several add-ons are showing an incorrect time (UTC-8)
    (for example, post to social media logs the posted-to time as UTC-8, and the volunteer page documents the time of the event as UTC-8)
    3- However – POSTS and PAGES (publish time, edit time, etc) display the correct time (UTC-4)

    The issue with the add-ons appears to be directly related to that item 1 is wrong… and the add-ons are using the same function that displays the timezone/time in the general settings (both add-ons that I list above told me to look at the general setting for timezone)

    Here’s something to check. Install the WordPress phpinfo() | www.ads-software.com plugin and once done, go to Settings -> PHP Info. Scroll down to the date section and check the following three values:

    
    Default timezone 	UTC 
    Directive	Local Value	Master Value
    date.timezone	America/Chicago	America/New_York
    

    Those are for my webserver which is in the Eastern Time zone.

    If I put that line back in my functions.php, the Default timezone changes to America/Chicago instead of UTC.

    So, you might try putting the following into your theme’s functions.php file:
    date_default_timezone_set('UTC');

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Hi. I can explain this. I rewrote a large part of the current timezone system in WordPress many years ago.

    WordPress was originally a PHP 4 application. PHP didn’t have good support for timezones. So back then, it didn’t have timezone support. It just had time, and a manual offset. Naturally, this was unpleasant when you had to change the clock twice a year.

    When PHP 5 support came out and started supporting timezones, we added this support to WordPress. At the time, PHP 4 was still supported, so this was augmented in the following manner. When timezone support by PHP is detected, then WordPress sets the default timezone to UTC, and uses the setting on the general settings page to calculate the offset itself. This offset is then applied using a WordPress filter to the points where it is needed.

    In short, WordPress does not use the native PHP support for timezones, but rather reimplements most of the time handling code internally, and uses the PHP timezone support only to calculate an offset.

    So, when you change the default timezone for PHP, you change the underlying assumption that WordPress is using (default timezone is UTC) and thus get an overcorrection.

    By and large, this is something that needs to be fixed in WordPress. There’s probably a few trac tickets for it. However, it is no small project, and while it would likely be a considerable speed improvement, it has not been a priority. Basically rewriting everything to eliminate all the extra code and such only to end up in the same place that you started, and potentially breaking plugins and other code that makes the same assumptions WordPress does, isn’t currently something somebody has tackled.

    TL; DR: WordPress calls date_default_timezone_set('UTC') in the wp-settings.php file, very early. If you change it at any point after that, then WordPress will overcorrect the timezone calculation. Either don’t change it, or change it back once you’ve finished doing whatever you’re doing.

    Ah.. thanks for the explanation. Things make a lot more sense now.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘more UTC issues in WordPress’ is closed to new replies.