cakephp / docs

CakePHP CookBook
http://book.cakephp.org
Other
679 stars 2.58k forks source link

clarify Date/Time object doesn't extend DateTimeInterface anymore #7894

Closed LordSimal closed 3 months ago

LordSimal commented 3 months ago

Caused by https://discourse.cakephp.org/t/comparing-date-with-datetime-in-cake-5/12166/4

othercorey commented 3 months ago

This isn't true. Chronos extends DateTimeImmutable which implements DateTimeInterface.

https://github.com/cakephp/chronos/blob/3.x/src/Chronos.php#L62

LordSimal commented 3 months ago

but ChronosDate and ChronosTime dont.

Therefore Date and Time can't be compared to \DateTime instances anymore (and are now silently always returning false as can be seen in the linked discourse thread)

Only DateTime extends Chronos and can therefore be directly compared to a \DateTime instance

othercorey commented 3 months ago

Ah ok. I misread Time as the previous Time/FrozenTime type which became DateTime which does implement DateTimeInterface.

othercorey commented 3 months ago

I would omit the Time type due to that confusion. We didn't have a time-only type before 5.0 and the previous Time type could be confusing.

LordSimal commented 3 months ago

true, I thought we had but i was wrong