Error in formating DateTime object. Expected DateTime, but instead given boolean

WordPress Event Management, Calendars & Registration Forums Report A Bug Error in formating DateTime object. Expected DateTime, but instead given boolean

This topic contains 2 replies, has 2 voices, and was last updated by  Benjamine Heath 1 month, 2 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #40590

    Hi,

    I’m using the shortcode [eo_fullcalendar] to display our calendar on this page: https://villagezendo.org/calendar/

    Periodically, the calendar gets hung up in perpetual loading, and I’ve found because the following call is returning an Error 500:

    https://villagezendo.org/wp-admin/admin-ajax.php?action=eventorganiser-fullcal&start=2021-10-31&end=2021-12-05&timeformat=g%3Ai%20a

    I’ve noticed that flushing our object cache temporarily resolves this issue, but the error still continues happening periodically. I’m definitely no server-side expert, but I thought that maybe this has to do with object caching on our server (since flushing it fixes it temporarily), so I disabled object caching on that page. However the error continues to persist periodically.

    I checked our PHP error logs and found the following:

    [28-Nov-2021 22:34:03 UTC] PHP Fatal error:  Uncaught Exception: Error in formating DateTime object. Expected DateTime, but instead given boolean in /srv/htdocs/wp-content/plugins/event-organiser/includes/event-organiser-utility-functions.php:31
    Stack trace:
    #0 /srv/htdocs/wp-content/plugins/event-organiser/includes/event-organiser-utility-functions.php(164): eo_format_datetime(false, 'F j, Y  g:i a')
    #1 /srv/htdocs/wp-content/plugins/event-organiser/includes/event-organiser-ajax.php(179): eo_format_event_occurrence(20043, 0, 'F j, Y ', 'g:i a', ' - ', false)
    #2 /wordpress/core/5.8.2/wp-includes/class-wp-hook.php(303): eventorganiser_public_fullcalendar('')
    #3 /wordpress/core/5.8.2/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters('', Array)
    #4 /wordpress/core/5.8.2/wp-includes/plugin.php(470): WP_Hook->do_action(Array)
    #5 /wordpress/core/5.8.2/wp-admin/admin-ajax.php(187): do_action('wp_ajax_eventor...')
    #6 {main}
      thrown in /srv/htdocs/wp-content/plugins/event-organiser/includes/event-organiser-utility-functions.php on line 31
    [28-Nov-2021 22:35:22 UTC] PHP Fatal error:  Uncaught Exception: Error in formating DateTime object. Expected DateTime, but instead given boolean in /srv/htdocs/wp-content/plugins/event-organiser/includes/event-organiser-utility-functions.php:31
    Stack trace:
    #0 /srv/htdocs/wp-content/plugins/event-organiser/includes/event-organiser-utility-functions.php(164): eo_format_datetime(false, 'F j, Y  g:i a')
    #1 /srv/htdocs/wp-content/plugins/event-organiser/includes/event-organiser-ajax.php(179): eo_format_event_occurrence(20043, 0, 'F j, Y ', 'g:i a', ' - ', false)
    #2 /wordpress/core/5.8.2/wp-includes/class-wp-hook.php(303): eventorganiser_public_fullcalendar('')
    #3 /wordpress/core/5.8.2/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters('', Array)
    #4 /wordpress/core/5.8.2/wp-includes/plugin.php(470): WP_Hook->do_action(Array)
    #5 /wordpress/core/5.8.2/wp-admin/admin-ajax.php(187): do_action('wp_ajax_eventor...')
    #6 {main}
      thrown in /srv/htdocs/wp-content/plugins/event-organiser/includes/event-organiser-utility-functions.php on line 31

    Can you please help?

    Thanks,

    Ben

    Benjamine Heath
    #40592

    Hi Ben,

    This generally happens if the event has no dates. In my experience it can happen if you have another events plug-in installed, or you if you have switched from another and you had some existing events from that plug-in.

    In this instance I can see this line is being called with the occurrence ID set to 0. The event in question is 20043. It may be worth checking the eo_events table for any rows with post_id set to 20043.

    If it does then I would next check the query being run (this is an excellent plugin for that: https://wordpress.org/plugins/query-monitor/). It might be there is another plug-in interfering with the database query.

    However, since you mentioned that clearing object cache seems to fix this issue, then its likely event queries are being cached, and I suspect the cached results are missing the occurrence ID. When required, the plug-in modifies database queries for events to join the event dates, but if the caching is being done before that, then its possible its caching a previous query which didn’t join the event dates. The plug-in then caches the calendar, so this would explain why it might work for a while.

    I’m not sure how granular, but if you can disable the caching for a post type, you might find that resolves the issue. However, typically with object caching it works at the database query level.

    Stephen Harris
    #40595

    Hi Stephen,

    Thanks so much for your detailed response—this is very helpful.

    I installed Query Monitor and this is was the response from admin-ajax.php when it gave the latest 500 error:

    Fatal error: Uncaught Exception: Error in formating DateTime object. Expected DateTime, but instead given boolean
    in /srv/htdocs/wp-content/plugins/event-organiser/includes/event-organiser-utility-functions.php on line 31
    
    Call stack:
    
    eo_format_datetime()
    wp-content/plugins/event-organiser/includes/event-organiser-utility-functions.php:164
    eo_format_event_occurrence()
    wp-content/plugins/event-organiser/includes/event-organiser-ajax.php:179
    eventorganiser_public_fullcalendar()
    wp-includes/class-wp-hook.php:303
    WP_Hook::apply_filters()
    wp-includes/class-wp-hook.php:327
    WP_Hook::do_action()
    wp-includes/plugin.php:470
    do_action()
    wp-admin/admin-ajax.php:187
    

    I did a search in our DB for the latest post_id that returned the error, and I found these entries:

    Is one of the event_occurrence’s supposed to be 0, and is that occurrence id throwing the error? If it is, it seems that occurrence id works fine normally….. but when it’s cached, 0 is read as a boolean? (shot in the dark, I’m a little out of my depth)

    I spot checked a few other events, and many events have their event_occurrence as 0.

    Thanks so much for your help,

    Ben

    Benjamine Heath
Viewing 3 posts - 1 through 3 (of 3 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.