Skip to content

[6.x] Fix localized dates leaking into later template usages - #15224

Open
duncanmcclean wants to merge 1 commit into
6.xfrom
copy-dates-before-localizing
Open

[6.x] Fix localized dates leaking into later template usages#15224
duncanmcclean wants to merge 1 commit into
6.xfrom
copy-dates-before-localizing

Conversation

@duncanmcclean

@duncanmcclean duncanmcclean commented Aug 20, 2026

Copy link
Copy Markdown
Member

This pull request fixes an issue where date modifiers would ignore localize_dates_in_modifiers => false and output dates in the display timezone — but only when the same date had already been output plainly earlier in the template.

This was happening because Carbon instances are mutable, and a dated entry's date is a single memoized instance shared by every usage in the template. The Localize middleware's toStringFormat callback called setTimezone() on it directly, so the first plain {{ date }} output shifted the shared instance into the display timezone and every later modifier saw the shifted date. (Date fieldtype values weren't affected, since augmentation creates a fresh Carbon instance on each access — which is why the behaviour seemed inconsistent between fields.)

This PR fixes it by copying the date before localizing it, both in the middleware's toStringFormat callback and in CoreModifiers::carbon(), which had the same mutation in the other direction when localize_dates_in_modifiers is enabled.

Fixes #13869

Carbon is mutable and a dated entry's date is a single memoized instance,
so calling `setTimezone()` in the `Localize` middleware's toString format
(or in `CoreModifiers::carbon()` when `localize_dates_in_modifiers` is
enabled) leaked the localized timezone into every later usage of the same
date within the request.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected result using {{ date }} and setting 'localize_dates_in_modifiers' => false

1 participant