Time zone problem in Appointments+

When I click on an open timeslot for a worker, the time displayed is always 4 hours behind the time that comes up in the confirm appointment box. I tested this specifically with an appointment on June 30 at 10:30 am.

I did change my WordPress Timezone to America/New_York. I also set my server to EST, as well as MySQL to EST.

I’ve been running tests on where this time problem pops up by manually calling up the time in question in various places in the website. The function I call is date(“l, F j, Y, g:i a e”,1372602600 ); That number is the timestamp for June 30, 10:30 am.

I called that function in various other places in the appointments.php file. It called the correct time everywhere I’ve put it EXCEPT in the ajax call that creates the final time listed in the appointments confirm box. This function is called pre_confirmation. The function is located in appointments.php on line 2228.

On line 2257, the timestamp is converted to a readable date with the function

apply_filters( ‘app_confirmation_start’, date_i18n( $this- >datetime_format, $start ), $start )

I suspected maybe the function date_i18n could be the problem, so I replaced this statement with date(“l, F j, Y, g:i a e”,1372602600 ). This produced the exactly same error – the time was put 4 hours ahead.

I have read other responses to this question of the timezone problems, and the only answer seemed to be to disable other plugins. I have disabled all plugins except those that are absolutely necessary to the site.

Is there a way to change the timezone within this function? Or do you know where and how the timezone is set within this and/or other ajax calls?

Thanks so much!

  • finchman
    • Flash Drive

    I found a very dirty solution to this problem – I added the following line of code before any other things in that function are called.

    date_default_timezone_set( get_option(‘timezone_string’:wink: );

    get_option(‘timezone_string’:wink: -> Gets the option for the default timezone set in wordpress.

    Now, in the confirm appointment box, the correct time is displayed. However, later, when viewing the appointments in the approved appointments dialog eslewhere on my site, it is still set 4 hours too far. I’m guessing that I can solve this problem by putting this same line of code in other places in other functions.

    Is there a better, less hacky solution to this problem?

  • finchman
    • Flash Drive

    Added the same statement to the function post_confirmation on line 2328

    date_default_timezone_set( get_option(‘timezone_string’:wink: );

    This seems to insert the timestamp correctly into the database, and display it properly in other contexts on the site.

    Please let me know what you all think of this solution, or if anybody else came up with a better solution.

  • finchman
    • Flash Drive

    Also added the same line of code( date_default_timezone_set( get_option(‘timezone_string’:wink: ); ) to the function that calls the appointments shortcode itself. this is the function “my_appointments” on line 1340 in appointments.php

    This, in combination with setting WordPress’s default setting to eastern time, as well as the linux server and the mysql server, seems to have solved the problems – times are displaying properly, and being submitted into the database properly.