-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
Carbon use parse method #6183
Carbon use parse method #6183
Conversation
…l missing usecases
Another solution is limit the possible values passed as arg, and skip transformation if not match yet, so the existing functionality not changed, if there is different arg pattern, it should be skipped instead to be added later |
@samsonasik You are correct. It's better to keep the existing add/sub in case the regex matches. |
Hey @TomasVotruba, The CI now passes. I had some trouble running this locally so had to push a few times 😄 Basically it can now create a correct carbon date for most common cases and what we cannot parse to a correct Carbon method we let their native parse function handle. Can you review this PR? Had some trouble by changing the first static call I solved this by using references but this didn't pass the static tests. |
@TomasVotruba i.m.o it might be better to not use the setDate, setTime & setDateTime functions like I have now and just handle those with parse. when I have a date like $date = new \DateTime('2024-01-02'); I rather have this as the result $date = \Carbon\Carbon::parse('2024-01-02'); Instead of what I do now $date = \Carbon\Carbon::now()->setDate(2024, 1, 2); Having the parse functionality is most neat with the original and is better for creating dates |
Looks good! It's also keep original format, that makes is more smoother to migrate to |
@TomasVotruba, It is now done for review/merge, I removed the setDate & setTime function. I've also added an extra configure rule to this ruleset, this will Rename new \DateTime to new \Carbon\Carbon for cases where the argument is not a string, but might be another date object. |
rules-tests/Carbon/Rector/New_/DateTimeInstanceToCarbonRector/Fixture/some_class.php.inc
Outdated
Show resolved
Hide resolved
rules-tests/Carbon/Rector/New_/DateTimeInstanceToCarbonRector/config/configured_rule.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
Looks good! @florisbosch Thank you for your amazing work 👏 |
Yesterday I made a pull request (#6176) to fix some extra cases for add / sub hours, minutes and seconds.
This fix wasn't reliable enough since the amount of options you can specify in \DateTime is much more than what we have now. To fix this problems we can use the parse method in Carbon this should be an drop-in replacement of \DateTime.
I think it's best to start with this for now our base Carbon ruleset.
In future releases we can extend this and create extended sets to convert to Carbon specific functions like addX and subX but only if all cases are handled.
Also this change now includes specific times that have been set and if we have a rest string for the date we change the original static call to a parse