Comments (10)
And somes holydays (like Easter) are not same dates each year.
I think you better have to do your own extension :
MyCarbon extends Carbon {
public function isHoliday() {
return in_array([ $this->month, $this->day ], [
[12, 25], // Christmas
[01, 01], // New Year
...
]);
}
}
from carbon.
I think what Carbon needs is a macro functionality so you can add your own feature over it. If you need to define the holidays yourself this is pretty much what this would be.
Carbon::macro('isHoliday', function ($date) {
return in_array($date->format('Y-m-d'), [holidays]);
});
Carbon::parse('some-date')->isHoliday();
Something like that, that would allow people to add helpers for their edge cases, what do you think @briannesbitt ?
from carbon.
That would be incredibly complicated, do you know how many days are considered holidays all countries combined ?
from carbon.
I think, but if we would use, we can add a config array of days for example:
'Christmas' => [12,25], //to repeat festive days every year
'New Year' => [01,01],
'my festive' => [2014,05,01] //to only day timely festive
from carbon.
great! thanks!
from carbon.
There is a set of packages that is trying to solve just that.
https://github.com/Altruja/workday which makes use of https://github.com/Mayflower/libholiday
from carbon.
Good luck with that, incredibly complicated to do something like that! BTW, christmas in Germany is always the 24th of December, not the 25th.
from carbon.
I rather this be done in a sub class than adding macro functionality. If it then becomes flushed out and useful for others (and a common issue) then we can look at pulling it in.
from carbon.
I created a PR which adds Carbon extensions that check to see if a given date is a business day. Custom holiday and business schedules can be provided which allow you to properly determine what the date is for next or previous number of business days.
from carbon.
Will appear in the documentation:
gh-pages...kylekatarnls:gh-pages-1.26
from carbon.
Related Issues (20)
- Proposal to remove hard dependency on carbonphp/carbon-doctrine-types HOT 4
- Deprecation: Implicit conversion from float to int loses precision HOT 1
- PHPDoc on `CarbonImmutable::createFromFormat` incompatible with actual return type HOT 2
- Feature request: Support Symfony Forms HOT 4
- Carbon 3 createFromTimestamp undocumented timezone change HOT 2
- Bug: CarbonImmutable::createFromTimeString('first day of this year 00:00:00') returning February 1st instead of January 1st HOT 2
- [Translation tool] bg HOT 1
- Method isFuture returns an incorrect result HOT 3
- Wrong issue! HOT 1
- Format "2024-02-29" to Buddhist Era so to obtain "2567-02-29" HOT 4
- Taiwan is NOT the Province of China HOT 9
- [Removed]
- Can't get the UTC+0 timestamp HOT 1
- Both Hong Kong and Macao are the Special Administrative Regions of China HOT 5
- isSameUnit not working like in previous versions and accepting "null" as argument HOT 8
- createFromTimestamp does not respect the default timezone HOT 4
- Can no longer use `createFromFormat` with an non-string value as time input HOT 5
- Error addRealSeconds HOT 4
- The output of diffInMonths is indeed incorrect HOT 1
- Carbon v3 diffInDays is not consistent HOT 3
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.