Support » Plugin: My Calendar » Time difference, locale probem

  • Resolved arijuki

    (@arijuki)



    When testing you calendar plugin, I noticed that now (almost midnight here in Finland), your calendar started showing that it is already 5 March, although it is still 4 March.

    I checked date-utilities.php and did some testing, regarding function mc_dateclass( $current ).

    Test:

    $now      =  current_time( 'timestamp' );
    $dayclass = sanitize_html_class( strtolower( date_i18n( 'l', $now ) ) ) . ' ' . sanitize_html_class( strtolower( date_i18n( 'D', $now ) ) );
    $date = date( "Ymd", $now );
    $time = date("D M j G:i:s T Y", $now);
    echo $now . '<br>';
    echo $dayclass . '<br>';
    echo $date . '<br>';
    echo $time;

    Result:

    1520206916
    maanantai ma (this is "Sunday su" in Finnish)
    20180305
    Mon Mar 5 1:41:56 EET 2018

    Command line:

    date
    Sun Mar  4 23:41:56 EET 2018

    Two hours difference although time zone (EET) is the same?

    • This topic was modified 8 months, 2 weeks ago by  arijuki.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Little more further testing… Also noticed that I made a small mistake above, obviously aI mentioned:
    maanantai ma (this is "Sunday su" in Finnish)
    should be
    maanantai ma (this is "Monday Mo" in Finnish)

    So I am not sure if this is locale or what issue, but findings are below.

    Using date () instead of current time:
    $now2 = date("U");

    will result in:

    1520206798
    maanantai ma
    20180305
    Mon Mar 5 1:39:58 EET 2018

    when current_time() results in:

    1520213998
    maanantai ma
    20180305
    Mon Mar 5 3:39:58 EET 2018

    There is two hours difference because of something. I am not really an expert coder but my two cents 🙂

    • This reply was modified 8 months, 2 weeks ago by  arijuki.
    Plugin Author Joe Dolson

    (@joedolson)

    current_time() returns the current time according to your WordPress settings, where the date() function in PHP will return the time according to your server. What time zone is set in your WordPress time zone settings?

    I have VPS and time zone is set to Helsinki, Finland (EET) in both, VPS and WordPress. But for me current time does not seem to work?

    WordPress is telling (again in Finnish, but first UTC and then local):
    Koordinoitu yleisaika (UTC) on 2018-03-05 07:06:04. Paikallinen aika on 2018-03-05 09:06:04.

    I can try to debug if you tell me what to do, this is getting above my skill level 🙂

    • This reply was modified 8 months, 2 weeks ago by  arijuki.
    • This reply was modified 8 months, 2 weeks ago by  arijuki.
    • This reply was modified 8 months, 2 weeks ago by  arijuki.
    Plugin Author Joe Dolson

    (@joedolson)

    Is the time correct on your server? Is the timezone in WordPress actually set to a locale, or to a numeric offset?

    Current time is dependent on your server time – it gets the time from your server, than modifies it to adjust for your timezone settings within WordPress. It’s entirely reasonable that the two times would be different.

    You can ignore the timezone output in your formatted dates (EET). Current_time() only returns an absolutely UNIX time value, so it can’t actually render the correct timezone; that will still come from your server settings, regardless of the time used.

    Actually I was playing with locale and offset and now time is right 🙂 I really don’t know what happened, as nothing was changed except those. Also time on server is correct. I have locale set Helsinki/Europe in WordPress settings.

    BUT … The reason I started looking at the problem is that when I am using Mini Widget, at 22.00 in the evening it thinks that it is already next day (you can see it from current-day which is used e.g. for background-color. I thought that the problem would be in that function mentioned above, but perhaps I was wrong. This problem is only visible for two last hours of the day, between 22.00-00.00. Perhaps you have an idea what could cause it?

    You can see the Mini Widget here in the footer – https://katja.arijuki.net/ We are not live yet so the address is temporary. I have also removed separate background-color for current day for now.

    Plugin Author Joe Dolson

    (@joedolson)

    I can’t see your site at that location, so I can’t see anything there.

    That issue would be connected to identifying the current day, so that’s the function that’s most directly relevant. Usually, any problem with that is resolved by fixing your time zone. It compares the current day being viewed with the current timestamp according to WordPress.

    That is because i just changed the domain – https://katjakarjalainen.com/

    Problem solved, this is a plugin conflict. Another plugin must be setting timezone to something else than UTC.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Time difference, locale probem’ is closed to new replies.