Time & Date Deprecated

in Cakephp 4.3

The datetime classes Time and Date are deprecated. 
Use their immutable alternatives FrozenTime and FrozenDate instead.

I find Time & Date kinda useful. Is there a reason why Time & Date is deprecated ?

What do you find useful about them, which FrozenTime and FrozenDate can’t do?

FrozenTime and FrozenDate are basically the same as Time and Date, just that they are immutable.

yes, i am aware of frozenDate/Time are immutable objects. It would be an extra step for me to change the date/time as frozenDate/Time creates a new instance when changed. An extra step for me.

Just curious why it is deprecated, since Time/Date has been there for so long.

I think it’s because of the number of bugs that people get when they do things like $entity->some_date->addYear()->format('xxx') to generate a readable version of a year after the date in question, without realizing that this changes the date in the entity. Making everything immutable means that you have to make your intention clear when you want to change it.

1 Like