Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Fix carbon deprecation warning #11561

Merged
merged 1 commit into from
Mar 11, 2025
Merged

[5.x] Fix carbon deprecation warning #11561

merged 1 commit into from
Mar 11, 2025

Conversation

jasonvarga
Copy link
Member

@jasonvarga jasonvarga commented Mar 11, 2025

Fixes #11553

This is already fixed in v6 but this backports it.

Context:

try {
    return Carbon::createFromFormat($this->saveFormat(), $value);
} catch (InvalidFormatException|InvalidArgumentException $e) {
    return Carbon::parse($value);
}

Sometimes $value is already a Carbon instance.
When you pass a Carbon instance to createFromFormat, you get an InvalidFormatException.
The catch will catch it, and pass the Carbon instance into parse, which just returns the instance back and logs the deprecation warning. We can avoid all that by just returning a Carbon instance early.

@jasonvarga jasonvarga merged commit 68c61a9 into 5.x Mar 11, 2025
27 checks passed
@jasonvarga jasonvarga deleted the date-deprecation branch March 11, 2025 20:39
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.

Carbon deprecation warning triggered in date fieldtypes parseSaved function
1 participant