[Solved] FrozenTime object mistery

I found a strange case in a FrozenTime object.

I get data from a find() and I send it to the view as usual. One particular field comes from a MySQL time column.

The table name is sessions and the field is called time.

When iterating the resulset, this column becomes:

object(Cake\I18n\FrozenTime) {

	'time' => '2017-07-14T01:00:50+00:00',
	'timezone' => 'UTC',
	'fixedNowTime' => false

}

The mistery starts when calling debug($session->time->format('G:i:s')); With this, I get a Call to a member function format() on null error.

While trying to solve the issue, I did:

$moment = $session->time;
debug($moment instanceof \Cake\I18n\FrozenTime);

and I got a true as an answer. Strange to be null (as the error says) if it is actually an object with content. And I expect to be able to run a ->format() on a FrozenTime object.

It’s even more strange when running:

$b = new Cake\I18n\FrozenTime($moment);
debug($b);
debug($moment == $b);

debug($b); returns the same object(Cake\I18n\FrozenTime) showed above, and debug($moment == $b); returns true. And, guess what? $b->format('G:i:s'); works at this point and it returns something like 1:00:50 (as I was expecting when calling $session->time->format('G:i:s'));

Is it a bug? Am I doing something wrong? Why two equal objects behavior in a different manner?

Should I rename the table and/or the field?

Any help will be appreciated. Thank you.

Solved!

Simple fact: the error was triggered just because ONE time column was returning NULL

It looks easy when you see it :rofl:

Hey Guys, I am having same kind of problem, I am from india and i am giving data on ui as per indian timing but after going to patchEntities method it is returning as frozen time object and not getting the proper time what i given in UI. Can i get help for this

Show us the code that’s doing the patching, the raw incoming data, and the result after patching.

05:00 UTC = 10:30 Kolkata, and 12:30 UTC = 18:00 Kolkata, right? So the problem seems to be one of time zone handling. Normally, what will happen is that you’ll have UTC times saved in your database, and they get converted to and from local time when reading and writing.

I see you’re calling date_default_timezone_set at the start of your function. In the “standard” setup, that’s instead called from config/bootstrap.php, using a value set in config/app.php. Also, you should be setting the same timezone value in your datasource configuration.

And if you do any manual connection to the database (command line, phpMySQL, etc.), make sure that it’s also configured for your timezone, so that you see query results that match what you expect.

Hi Team, I have added date_default_timezone_set in the bootstrap.php but the issue is still same. is it possible to not get the time as frozentime object instead i can directly enter the test what i have entered in the UI. By the way i am using time() validator in the table.php file under Model Folder and Table Section Sorry for the late response.

Are you setting the timezone in your datasource configuration?

yeah got it… i have to edit the application configuration in the bootstrap.php. i have edited to Asia/kolkata timezone. Thanks a lot.