Help Desk

Different timezone causes event to prematurely be marked as passed.

  • Posts: 15 Topics: 8
    | Permalink

    Hello,

    Most of our events are in the central timezone. Our site is set to use “Chicago” for the timezone under Settings -> General.

    We do have a handful of events that are marked as different timezones. These events are marked as “passed” before the event time passes. You can see in the attached screenshot — taken at 9:30AM CENTRAL — that the PDT event should not have passed yet. The event is from 8:30AM – 9:00AM PDT … or 10:30AM-11:00AM CDT.

    TEC is set to “Use the local timezones for each event.” More relevant screenshots attached, including testing with Twentyseventeen.

    Is this a bug or is there just a weird configuration issue somewhere that I am missing?

    Thanks,

    Tim

    Posts: 15 Topics: 8
    | Permalink

    After digging into this more, it seems as though the tribe_is_past_event function just doesn’t check an event’s timezone when determining if it has passed. It only looks at the gmt_offset option.

    Here is an example of what could theoretically fix the problem. I’m not sure what the implications of something like this would be on other functions of the site or with different plugin configurations, but it seems like a good start. Any ideas on how something like this could be implemented in a way that doesn’t involve modifying the plugin myself?

    	/**
    	 * Detect if an Event is Past
    	 *
    	 * Returns true if the current time is past the event end time
    	 *
    	 * @param null $event
    	 *
    	 * @return bool
    	 */
    	function tribe_is_past_event( $event = null ) {
    
    		if ( is_null( $event ) ) {
    			global $post;
    			$event = $post;
    		}
    		
    		$timezone = Tribe__Events__Timezones::get_event_timezone_string($event->ID);
    		
    		if ($timezone) {
    			$time = new \DateTime('now', new DateTimeZone($timezone));
    			$timezoneOffset = intval(str_replace(':00', '', (string) $time->format('P')));
    		} else {
    			$timezoneOffset = get_option( 'gmt_offset' );
    		}
    		
    		// Check if event has passed
    		$gmt_offset = ( $timezoneOffset >= '0' ) ? ' +' . $timezoneOffset : ' ' . $timezoneOffset;
    		$gmt_offset = str_replace( array( '.25', '.5', '.75' ), array( ':15', ':30', ':45' ), $gmt_offset );
    
    				
    		if ( strtotime( tribe_get_end_date( $event, false, 'Y-m-d G:i' ) . $gmt_offset ) <= time() ) {			
    			return true;
    		}
    
    		return false;
    
    	}
    Posts: 15 Topics: 8
    | Permalink

    It seems my above suggested solution really only works for the single event page, not upcoming event queries. When upcoming events are queried the database is checked for _EventEndDate, which won’t work if the server is set to a different timezone than the event.

    Why not convert current time to UTC and do all queries based on _EventEndDateUTC? I am sure this is not as simple as I’m suggesting, but seems like the only way to create true local timezone support.

    It seems that currently the only working solution is to use the same timezone sitewide rather than displaying localized timezone, which is less than ideal for the visitor. Please let me know if you have any other suggestions.

    Posts: 6978 Topics: 2
    | Permalink

    Hello Tim,

    Thanks for reaching out to us and for going so deep with this question.

    Also thanks for your suggestion. I will need to do some investigation on this if I can get you a quick solution. One rough workaround would be looking for _EventEndDate + 12 hours (or something like that) in the queries. This way some past events will be shown too, but at least the events which are not passed yet will show too. Would that work for you?

    Cheers,
    Andras

     

    Posts: 15 Topics: 8
    | Permalink

    Andras,

    That is less than ideal but would be an ok temporary solution. It’s better than switching the whole site to one timezone for us. Do you know if there are plans to fix this in the future?

    Thanks,

    Tim

    Posts: 6978 Topics: 2
    | Permalink

    Hi Tim,

    We do try to fix every bug that are found in our plugins. We continuously evaluate the reported bugs based on different factors to decide which one will make it into the next maintenance release.

    I have logged a bugticket for this and will be evaluated after the next maintenance release. So at the moment I cannot give you a fixed date when this is going to be fixed.

    You can ping me after the next MR (in about 2-3 weeks) and I can give you an update on the status. Until then I am going to set the status of this ticket to “pending fix”.

    If you have any new questions or issues please create a new ticket and reference this one.

    Thanks for your patience!

    Cheers,
    Andras

    Posts: 15 Topics: 8
    | Permalink

    Thanks for the information. I’ll check in at a later time.

    Posts: 6978 Topics: 2
    | Permalink

    You’re very welcome!

    Cheers,
    Andras

    Posts: 6230 Topics: 17
    | Permalink

    Hi Tim!

    Just wanted to share with you that a new maintenance release (for the Week of 5 March 2018) is out, including a fix for this issue 🙂

    Find out more about this release → https://theeventscalendar.com/maintenance-release-week-5-march-2018/

    Please update the plugins and let us know if the fix works for your site.

    Best,
    Victor

    Posts: 65
    | Permalink

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

    | Permalink

The topic ‘Different timezone causes event to prematurely be marked as passed.’ is closed to new replies.