Comments (7)
Carbon objects are DateTime objects.
from carbon.
But a "Carbon" in parameter type do not allow DateTime (non-Carbon) to be passed.
patie, you can extends this method safely with :
public function diffInDays(DateTime $dt = null, $abs = true) { $dt = ($dt === null) ? static::now($this->tz) : new Carbon($dt); return intval($this->diff($dt, $abs)->format('%r%a')); }
With doing new Carbon($dt), you're sure $dt will be a Carbon object even if a pure DateTime is passed.
from carbon.
@Anahkiasen :)
im talking about this..
$today = new \DateTime();
$tommorow = new Carbon;
echo $tommorow->diffInDays($today);
Catchable Fatal Error: Argument 1 passed to Carbon\Carbon::diffInDays() must be an instance of Carbon\Carbon, instance of DateTime given
if i have DateTime object from ORM for example.. i must transfer this DateTime into Carbon first to use.. but understand
from carbon.
The ->diff method is not overrided by Carbon so It could be changed by \DateTime with no consequence.
from carbon.
thx, but imho all can be working with DateTime always, now its not possible because BC, but maybe will be better always receive DateTime object (or better interface), and if its needed into method convert into Carbon, process Carbon and again return DateTime - so i know i always inject and get DateTime.
DateTime (controller) -> Carbon (carbon lib) -> DateTime (controller)
and i dont must convert this in controller, service whatever (clean and slim), because library do this for me. its ONLY IDEA, maybe not possible (i dont look at full source), and as i say BC is not welcome for sure.
from carbon.
Don't think simply changing the parameter type will work. If you actually pass in a DateTime it will try to call methods on the object that don't exist.
from carbon.
Going to close this for now. Most of the popular frameworks now use Carbon natively.
from carbon.
Related Issues (20)
- Incorrect totalSeconds after adding interval to CarbonInterval in v3 HOT 1
- Period `start` and `end` always wrong with Carbon 3 HOT 3
- Carbon ->toPeriod with interval / duration string fails after 3.2.1 version HOT 1
- Carbon v3 Documentaion for diffIn* methods HOT 2
- More granular v2 to v3 upgrade documentation? HOT 3
- [Translation tool] bs HOT 2
- diffForHumans() gives incorrect wording for SLOVAK language HOT 1
- Type error when calling canBeCreatedFromFormat with null date HOT 3
- diffInDays returns a float HOT 7
- Not working after download zip file HOT 1
- Serialization of 'Closure' is not allowed HOT 2
- Invalid CarbonInterval->format() results for Carbon 3 (unknown). HOT 8
- It is not possibble to upgrade Symfony 6.4 to 7.0 without upgrading Carbon from 2 to 3 HOT 1
- Carbon::now after Carbon::setTestNow gives incorrect results HOT 1
- Please don't modify existing instances with date arithmetic methods HOT 1
- Unknown or bad timezone (:/etc/localtime) HOT 2
- Carbon::createFromFormat Incorrect Month Output for February HOT 1
- Error parsing date HOT 1
- Unserialize from Carbon v2 objects HOT 1
- Carbon createFromTimestampMs no default time zone if it is set in env variable of Laravel app HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from carbon.