-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Best way to transform \DateTime in \Carbon #231
Comments
Right from the docs.... Finally, if you find yourself inheriting a \DateTime instance from another library, fear not! You can create a Carbon instance via a friendly instance() function. $dt = new \DateTime('first day of January 2008'); // <== instance from another API
$carbon = Carbon::instance($dt);
echo get_class($carbon); // 'Carbon\Carbon'
echo $carbon->toDateTimeString(); // 2008-01-01 00:00:00 Definitely makes me think we are in need of a separate website with better navigation ! |
It's unfortunate that My workaround:
|
As you can see:
If you still have trouble please fill a complete issue following the template so we'll have all informations we need to help you. |
@kylekatarnls thanks for explaining. Turned out we are running 1.22. We'll get to revise on what's stopping us from migrating to a newer version. |
New features require minor update in semantic version, that's why you should have |
The cleanest way is given in the very first example of the first chapter after intro in docs: $carbon = new Carbon($dateTime); It can't be more neat and I don't think we should add more alias for this. Also making all the features being guessable for preferences of everybody without having to read the doc isn't a challenge I would plan to try. Thanks. |
I've found this issue when I wanted to migrate |
Thank you @TomasVotruba! I think it can be pretty handy, mainly for people looking for a way to mock time in their tests for their existing code :) I suggest to also include the conversion for immutable dates: |
@kylekatarnls Makes sense, thank you 👍 :) |
Yep, I think I can suggest few things and might try to get PR for them. I see you have |
Sounds great 👍
I thought of that but wasn't sure about best practice. PR would be awesome 🙏 |
Hi there,
This is not a proper issue, but more a question : is there a proper way to transform a \DateTime object (often returned by third party library - like Doctrine in my case) to a Carbon powered object ?
As the constructor accepts the same arguments as \DateTime it is possible to format the \DateTime to a unambiguous string and send it to Carbon but it doesn't feel nice.
Keep up the good work
The text was updated successfully, but these errors were encountered: