[11.x] Ensure datetime cache durations account for script execution time #53431
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
This PR addresses a rounding bug when datetime or intervals are used with the cache.
Surprisingly, this will not put the value into the cache. It will instead call
Cache::forgetunder the hood.This is because by the time we do a diff between
now()and$ttl = now()->addSecond()some time has passed during PHP execution, even if only microseconds. That means the diff is ~0.999 seconds, which we cast to anintresulting in0.This also impacts date time intervals, because we convert those to datetime instances.
I have a gut feeling this also impacts other parts of the framework where we pull the seconds off a datetime, such as the queue system. Also anything that uses
InteractsWithTimemay also be impacted. Some of those values are likely off by a second. I haven't investigated this to confirm, though.