Comments (6)
Ah yes. The "relative keyword" match is matching the minus signs incorrectly.
from carbon.
Fixed with a test. 21c4cb4
from carbon.
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.
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.
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.
I see, that makes sense. Thanks for clearing things up.
from carbon.
Related Issues (20)
- 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
- `CarbonInterval`'s `days` property return false HOT 2
- [Translation tool] sr_RS@latin
- Date difference problem HOT 5
- isSameDay: Too few arguments HOT 1
- Singular methods without parameters also work with parameters. It should not be as per the documentation. HOT 1
- Inconsistent Date Calculation When Adding Months Across February HOT 5
- Carbon\Carbon::rawAddUnit(): Argument #3 ($value) must be of type int|float, string given HOT 5
- Failed to parse time dd/mm/yyyy using parseFromLocale with Portuguese 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.