Skip to content
Advertisement

cakePHP use of I18 Time addMinutes function updates every related variable, not just the current instance

I’ve been trying to set start times for different flights of competitors. The addMinutes function seems to update every variable associated with the “ONE” I’m trying to alter. Is this the expected result, or am I missing something really simple?

Thanks for your assistance,

JavaScript

srcControllerTestsController.php (line 89)

‘BTIME: 9/14/21, 6:09 PM USETIME: 9/14/21, 6:09 PM’

‘ MYTIME: 9/14/21, 6:24 PM BTIME: 9/14/21, 6:24 PM USETIME: 9/14/21, 6:24 PM’

‘ MYTIME: 9/14/21, 6:39 PM BTIME: 9/14/21, 6:39 PM USETIME: 9/14/21, 6:39 PM’

‘ MYTIME: 9/14/21, 6:54 PM BTIME: 9/14/21, 6:54 PM USETIME: 9/14/21, 6:54 PM’

‘ MYTIME: 9/14/21, 7:09 PM BTIME: 9/14/21, 7:09 PM USETIME: 9/14/21, 7:09 PM’

‘ MYTIME: 9/14/21, 7:24 PM BTIME: 9/14/21, 7:24 PM USETIME: 9/14/21, 7:24 PM’

‘ MYTIME: 9/14/21, 7:39 PM BTIME: 9/14/21, 7:39 PM USETIME: 9/14/21, 7:39 PM’

‘BTIME: 9/14/21, 7:39 PM USETIME: 9/14/21, 7:39 PM’

‘ MYTIME: 9/14/21, 7:54 PM BTIME: 9/14/21, 7:54 PM USETIME: 9/14/21, 7:54 PM’

‘ MYTIME: 9/14/21, 8:09 PM BTIME: 9/14/21, 8:09 PM USETIME: 9/14/21, 8:09 PM’

Advertisement

Answer

All your variables, a_time, b_time, and use_time, point to the same object. Furthermore CakeI18nTime is mutable, so $mytime will also be the very same object.

If you want immutable time objects, use CakeI18nFrozenTime instead. The time manipulation methods of those objects will return new instances.

See also

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement