GithubHelp home page GithubHelp logo

Comments (6)

briannesbitt avatar briannesbitt commented on June 11, 2024

Ah yes. The "relative keyword" match is matching the minus signs incorrectly.

from carbon.

briannesbitt avatar briannesbitt commented on June 11, 2024

Fixed with a test. 21c4cb4

from carbon.

pesterhazy avatar pesterhazy commented on June 11, 2024

Thanks, the issue is fixed for me in 1.8.0!

Relatedly, is this the expected behavior?

[1] boris> Carbon\Carbon::setTestNow(Carbon\Carbon::createFromDate(2013,10,1));
 → NULL
[2] boris> echo new Carbon\Carbon . "\n";
2013-10-01 09:30:06

It correctly mocks the year/month/day, but takes the hour/minute/second from the current clock. That seems strange to me. If I do

Carbon\Carbon::setTestNow(new Carbon\Carbon("2013-10-1"));

instead, it does set the hour/minute/second to zero, as I expected.

from carbon.

pesterhazy avatar pesterhazy commented on June 11, 2024

Note too that this, rather than using setTestNow(new Carbon(...)), seems to be the preferred way of mocking the current datetime, given that

Carbon::setTestNow(Carbon::createFromDate(...))

is in readme.me.

from carbon.

briannesbitt avatar briannesbitt commented on June 11, 2024

Yes this is expected and documented. https://github.com/briannesbitt/Carbon#api-instantiation

createFromDate() will default the time to now. createFromTime() will default the date to today. The ctor passes through to the DateTime ctor and relies on its implementation.

You can always use create(2012,1,1,0,0,0) to set the time to zeros... or startOfDay().

setTestNow() takes a Carbon instance so you can use any methods available to create your test instance.

from carbon.

pesterhazy avatar pesterhazy commented on June 11, 2024

I see, that makes sense. Thanks for clearing things up.

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.