-
Notifications
You must be signed in to change notification settings - Fork 370
DateTimeImmutable objects cannot be used as arguments for DateTime faker functions like e.g. dateTimeBetween #947
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
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 1 week if no further activity occurs. Thank you for your contributions. |
Still an issue. |
We did not plan to change it here. Just convert it manually when it returns from faker? |
@pimjansen It would be quite easy to support DateTime and DateTimeImmutable there using the DateTimeInterface for instanceof checks. Currently it is only possible to use DateTime and string for most of those functions. See, e.g. or Where the function would work just as well if the instanceof check uses DateTimeInterface which means DateTime and DateTimeImmutable could be used as arguments. |
We wont change the behaviour in 1x so just change it before injecting |
@pimjansen Which is what I am doing currently. Just a bit annoying . However, I am fine with it not being changed in v1. But would be nice in v2 at least. Actually as there is a v2 branch already, I did not expect it before v2 anyway. I only added a reply to avoid the issue being closed because of the stale label:
However, if it is part of the planned feature list for v2, I guess the issue can be closed with a corresponding info. |
Summary
DateTime generators do not support passing a DateTimeImmutable object.
I know about the issue #512
However, I also noticed that one cannot pass a DateTimeImmutable object to e.g. dateTimeBetween.
This should be quite an easy fix without breaking changes.
It should be enough to change https://github.com/FakerPHP/Faker/blob/v1.24.1/src/Faker/Core/DateTime.php#L39 to check for DateTimeInterface and the rest should work as it is.
Same still applies to the 2.0 branch.
Versions
fakerphp/faker
The text was updated successfully, but these errors were encountered: