Skip to content

Conversation

@ajnsn
Copy link
Contributor

@ajnsn ajnsn commented Jan 30, 2026

The improved timezone handling introduced in PR #11409 causes a TypeError when CarbonImmutable instances are used:

Statamic\Http\Middleware\Localize::Statamic\Http\Middleware{closure}(): Argument #1 ($date) must be of type Carbon\Carbon, Carbon\CarbonImmutable given

The callback in the Localize middleware type-hints the parameter as Carbon\Carbon, but Laravel's Date facade can return both Carbon and CarbonImmutable instances depending on the application configuration. This also affects applications using custom DTOs that utilize CarbonInterface.

This PR replaces the Carbon\Carbon type hint with Carbon\CarbonInterface in both affected middleware classes. Since both Carbon and CarbonImmutable implement CarbonInterface.

Example

In our application, we have a custom EventData DTO that uses CarbonImmutable for all date properties:

    readonly class EventData
    {
        public function __construct(
            public CarbonImmutable $starts_at,
            public CarbonImmutable $ends_at,
            // ...
        ) {}
    }

We combine these external event DTOs with Statamic entries in our Events component, merging them into a unified collection.

@jasonvarga jasonvarga merged commit 69f29f4 into statamic:6.x Jan 30, 2026
12 checks passed
@ajnsn ajnsn deleted the fix-localize-carbon-callback branch January 30, 2026 16:56
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.

2 participants