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

Add support for custom date class via Date::use() #859

Merged
merged 1 commit into from
Dec 28, 2019

Conversation

mfn
Copy link
Collaborator

@mfn mfn commented Dec 21, 2019

Laravel 5.8 introduced a feature to support a custom date class via
Date::use(), see laravel/framework#25320

When e.g. using Date::use(CarbonImmutable) in a project, it means
all date casts are not returning \Illuminate\Support\Carbon anymore
but \Carbon\CarbonImmutable, which means all the generated type hints
for dates are now wrong.

This change tries to be still backwards compatible with Laravel < 5.8
which do not have the Date facade.

Laravel 5.8 introduced a feature to support a custom date class via
`Date::use()`, see laravel/framework#25320

When e.g. using `Date::use(CarbonImmutable)` in a project, it means
all date casts are not returning `\Illuminate\Support\Carbon` anymore
but `\Carbon\CarbonImmutable`, which means all the generated type hints
for dates are now wrong.

This change tries to be still backwards compatible with Laravel < 5.8
which do not have the Date facade.
@barryvdh barryvdh merged commit 0d1dd21 into barryvdh:master Dec 28, 2019
@barryvdh
Copy link
Owner

Thanks

@amcsi
Copy link

amcsi commented Mar 23, 2021

This unfortunately only is for the date type model properties. This does not make functions like now() show that it returns CarbonImmutable.

@mfn
Copy link
Collaborator Author

mfn commented Mar 23, 2021

This unfortunately only is for the date type model properties. This does not make functions like now() show that it returns CarbonImmutable.

Indeed, this PR is only for the models.

I think you're referring to the Facade, right? I don't use them so 🤷‍♀️

Since the projects I needed for made a final decision to move to immutable, we use CarbonImmutable::now() directly in the code anyway.

@amcsi
Copy link

amcsi commented Mar 23, 2021

I know a benefit to the facade is that it lets you easily swap out what the current time is considered to be.

I don't expect to you to fix this by the way. I rather just wanted to make sure people are aware of this fact.

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.

3 participants