# \[Solved\] FrozenTime object mistery

**URL:** <https://discourse.cakephp.org/t/solved-frozentime-object-mistery/2888>\
**Category:** Need Help\
**Created:** [July 14, 2017, 8:28pm UTC](https://discourse.cakephp.org/t/solved-frozentime-object-mistery/2888 "2017-07-14T20:28:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerpro](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rogerpro/32/466_2.png) [@rogerpro](https://discourse.cakephp.org/u/rogerpro)\
**Post date:** [July 14, 2017, 8:28pm UTC](https://discourse.cakephp.org/t/solved-frozentime-object-mistery/2888/1 "2017-07-14T20:28:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rogerpro](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rogerpro/32/466_2.png) [@rogerpro](https://discourse.cakephp.org/u/rogerpro)\
**Post date:** [July 15, 2017, 9:37am UTC](https://discourse.cakephp.org/t/solved-frozentime-object-mistery/2888/2 "2017-07-15T09:37:39Z")

</div>

Solved!

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

It looks easy when you see it 🤣

---

<div class="post-metadata">

**Author:** ![sairaghuram.n](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@sairaghuram.n](https://discourse.cakephp.org/u/sairaghuram.n)\
**Post date:** [November 24, 2023, 10:40am UTC](https://discourse.cakephp.org/t/solved-frozentime-object-mistery/2888/3 "2023-11-24T10:40:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [November 24, 2023, 2:45pm UTC](https://discourse.cakephp.org/t/solved-frozentime-object-mistery/2888/4 "2023-11-24T14:45:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [November 27, 2023, 2:36pm UTC](https://discourse.cakephp.org/t/solved-frozentime-object-mistery/2888/6 "2023-11-27T14:36:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sairaghuram.n](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@sairaghuram.n](https://discourse.cakephp.org/u/sairaghuram.n)\
**Post date:** [December 7, 2023, 7:27am UTC](https://discourse.cakephp.org/t/solved-frozentime-object-mistery/2888/7 "2023-12-07T07:27:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [December 7, 2023, 9:29pm UTC](https://discourse.cakephp.org/t/solved-frozentime-object-mistery/2888/8 "2023-12-07T21:29:17Z")

</div>

Are you setting the timezone in your datasource configuration?

---

<div class="post-metadata">

**Author:** ![sairaghuram.n](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@sairaghuram.n](https://discourse.cakephp.org/u/sairaghuram.n)\
**Post date:** [December 8, 2023, 9:08am UTC](https://discourse.cakephp.org/t/solved-frozentime-object-mistery/2888/9 "2023-12-08T09:08:32Z")

</div>

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