GithubHelp home page GithubHelp logo

Comments (7)

Anahkiasen avatar Anahkiasen commented on May 29, 2024

Carbon objects are DateTime objects.

from carbon.

kylekatarnls avatar kylekatarnls commented on May 29, 2024

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.

patie avatar patie commented on May 29, 2024

@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.

kylekatarnls avatar kylekatarnls commented on May 29, 2024

The ->diff method is not overrided by Carbon so It could be changed by \DateTime with no consequence.

from carbon.

patie avatar patie commented on May 29, 2024

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.

briannesbitt avatar briannesbitt commented on May 29, 2024

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.

briannesbitt avatar briannesbitt commented on May 29, 2024

Going to close this for now. Most of the popular frameworks now use Carbon natively.

from carbon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.