Support

Home Forums Event Espresso Premium get_i18n_datetime() on a non-object

get_i18n_datetime() on a non-object

Posted: May 12, 2016 at 10:08 pm


kellyjo

May 12, 2016 at 10:08 pm

A little less than a month ago, you guys helped me solve this issue:

https://eventespresso.com/topic/calendar-database-mismatch/

I was attempting some custom work on the Events Check-In page in which the date of the Event would be listed in the dropdown menu.

It was successful, however, recently, we migrated to a new server, and this code is no longer working. I’m wondering why it is no longer working, but really, I just need the code to work.

The file is EE_Event_Registrations_list_Table.class.php in caffeinated/admin/extend/registrations

Here is the error:

Fatal error: Call to a member function get_i18n_datetime() on a non-object

Any help would be greatly appreciated!


Tony

  • Support Staff

May 13, 2016 at 4:09 am

Hi there,

The error means you are calling a function on something other than an object.

I’m guessing your using something like this:

$datetime->get_i18n_datetime( 'DTT_EVT_start' );

and $datetime is not an object, maybe all datetimes have expired, it could be a few different thing but without seeing the code we can not provide any information.

However, whilst we can provide examples like I did in your previous post we can not provide support for custom code or modifying code functions/files within Event Espresso.


kellyjo

May 13, 2016 at 12:02 pm

Hey Tony,

I am just trying to call a feature that is already built in and you have already supplied some code that helped and worked.

I have tried your other line of code listed, and it also brought up an error to a non-object:

Fatal error: Call to a member function start_date() on a non-object

There are always events every day, every week, every month, so what would change that could cause such an error? I tried updating EE4 to the latest version for security reasons and bug fixes to see if that would fix the error, but it still occurs.

The code look like exactly how you provided it:


foreach ( $events as $evt ) {
//any registrations for this event?
$evtdatetime = EEM_Datetime::instance()->get_primary_datetime_for_event( $evt->ID(), $try_to_exclude_expired = true, $try_to_exclude_deleted = true);
$eventdate = $evtdatetime->get_i18n_datetime( 'DTT_EVT_start' );
$expired = $evt->is_expired();
if ( ! $evt->get_count_of_all_registrations() )
continue;
$evts[] = array(
'id' => $evt->ID(),
'text' => $evt->get( 'EVT_name' ), . ' ' . date("n/j/Y", strtotime($eventdate)),
'class' => $evt->is_expired() ? 'ee-expired-event' : ''
);
}

The line where $eventdate is erroring because of get_i18n_datetime.


Josh

  • Support Staff

May 13, 2016 at 1:23 pm

It wouldn’t hurt things if you add some sanity checks to your code e.g.

if ( $evtdatetime instanceof EEM_Datetime ) {
// code that uses $eventdate here
}


kellyjo

May 13, 2016 at 2:19 pm

Hey Josh,

Thank you for the sanity check.

After I set $evtdatetime, I add that code and what it shows is that an echo test isn’t even being processed.


Josh

  • Support Staff

May 13, 2016 at 2:41 pm

You might look a bit upstream in your code to make sure you have an event object.


kellyjo

May 13, 2016 at 11:16 pm

No other code had been changed on this page which makes it hard to figure out if there is an event object somewhere else. I wonder why the switch to a new server brought up that error.

If we go back to the original issue and try to grab it without the get_i18n_datetime() function, I am getting the UTC+0 DateTime from the database.

However, in my attempt to try and convert it to -6 hours UTC, the dates still appear to be off by about 24 hours. So dates that should appear for 5/15 are appearing as 5/14.

To try and find a workaround for the lack of the get_i18n_datetime code, I tried doing something like this:


$userTimezone = new DateTimeZone('America/Denver');
$utcTimezone = new DateTimeZone('UTC');
$myDateTime = new DateTime(get_event_date($evt->ID(), "Y-m-d"), $utcTimezone);
$offset = $userTimezone->getOffset($myDateTime);

get_event_date is a custom function that grabs the date using the Event ID directly from the database.

And then echoing out the code:

date('Y-m-d', $myDateTime->format('U') + $offset)

Even with the offset code, it is showing wrong dates.


kellyjo

May 14, 2016 at 12:11 am

This is randomly working again and I can’t even explain why, as the code is exactly as is, when Tony posted it, so there is no issues.

I’ll set this to resolved in a few days if everything continues to work properly.

The support post ‘get_i18n_datetime() on a non-object’ 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