Support

Home Forums Event Espresso Premium Time and date conflict on EE4

Time and date conflict on EE4

Posted: November 22, 2016 at 9:56 am

Viewing 6 reply threads


Meg Benedicte

November 22, 2016 at 9:56 am

For some reason you guys deleted my last post without informing me.
I’ve installed a new calendar plugin and the time has messed up for my events. It shows different time compared to what I select. The other plugins dev said it isn’t their issue and they can’t help. I also tried solution posted on other threads and it didn’t work for me.
can you please help me out so I can start use both the plugins


Josh

  • Support Staff

November 22, 2016 at 10:13 am

We didn’t delete your last post.

Anyway, I’m not sure which other plugin you are using, but if you open up the other plugin’s files in an IDE, you can look for use of the
date_default_timezone_set() function, and remove that code. See also:

https://vip.wordpress.com/documentation/vip-development-tips-tricks/use-current_time-not-date_default_timezone_set/


Meg Benedicte

November 22, 2016 at 11:26 am

wouldn’t that be a temporary fix? Like, if I update the other plugin, then my updates will be wiped off. Well, i’m using modern events calendar along with EE which is causing this problem


Tony

  • Support Staff

November 22, 2016 at 11:33 am

Yes it’s a temporary fix but as you mentioned the other developer is unwilling to help there is little else we can do.

WordPress (and therefor Event Espresso) rely on the server timezone to be set to UTC. Take a look here for more details:

https://weston.ruter.net/2013/04/02/do-not-change-the-default-timezone-from-utc-in-wordpress/

So if another plugin changes the timezone using date_default_timezone_set() it causes the problem as now the default time is not UTC, its whatever the plugin set it to. So then EE pulls the time (which now incorrectly has an offset applied) and applies an offset based on your date settings which throws out the dates/times.


Meg Benedicte

November 27, 2016 at 11:23 pm

Here’s the timezone related code snippet i found in MEC

/**
* Set default timezone of WordPress
* @author Webnus <info@webnus.biz>
* @return void
*/
public function set_timezone()
{
$timezone_string = $this->get_timezone();

// Setting the default timezone of WordPress
if(trim($timezone_string)) date_default_timezone_set($timezone_string);
}

/**
* Get default timezone of WordPress
* @author Webnus <info@webnus.biz>
* @return string
*/
public function get_timezone()
{
$timezone_string = get_option(‘timezone_string’);
$gmt_offset = get_option(‘gmt_offset’);

if(trim($timezone_string) == ” and trim($gmt_offset))
{
$seconds = $gmt_offset*3600;
$timezone_string = timezone_name_from_abbr(”, $seconds, 1);
}
elseif(trim($timezone_string) == ” and trim($gmt_offset) == ‘0’)
{
$timezone_string = ‘UTC’;
}

return $timezone_string;
}

/**
* Get GMT offset based on hours:minutes
* @author Webnus <info@webnus.biz>
* @return string
*/
public function get_gmt_offset()
{
$gmt_offset = get_option(‘gmt_offset’);

$minutes = $gmt_offset*60;

$hour_minutes = sprintf(“%02d”, ($minutes%60));
$hours = sprintf(“%02d”, (($minutes-$hour_minutes)/60));

return (substr($hours, 0, 1) == ‘-‘ ? ” : ‘+’).$hours.$hour_minutes;
}


Meg Benedicte

November 27, 2016 at 11:24 pm

what do you reckon i should change?


Josh

  • Support Staff

November 28, 2016 at 2:46 pm

You can try removing this line of code:

date_default_timezone_set($timezone_string);

Viewing 6 reply threads

The support post ‘Time and date conflict on EE4’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso