Comments (8)
Resolved!
define the extradays in config/global.php
return [
'extraworkdays' => ['2020-12-12', '2021-12-11'],
]
?>
And in BussinessCalendar.php
public function isBusinessDay()
{
$mixin = $this;
/**
* Checks the date to see if it is a business day (neither a weekend day nor a holiday).
*
* @return bool
*/
return function ($self = null) use ($mixin) {
$carbonClass = @get_class() ?: Emulator::getClass(new \Exception());
/** @var \Carbon\Carbon|\Cmixin\BusinessDay $self */
$self = $carbonClass::getThisOrToday($self, isset($this) && $this !== $mixin ? $this : null);
//array of dates put in config global.php
$ex = config('global.extraworkdays');
if (in_array( $self->format('Y-m-d'), $ex)) {$except = true;} else {$except = false; }
return ($self->isWeekday() or $except) && !$self->isHoliday();
};
}
that's all.
from business-day.
for multiple date exceptions:
public function isBusinessDay()
{
$mixin = $this;
/**
* Checks the date to see if it is a business day (neither a weekend day nor a holiday).
*
* @return bool
*/
return function ($self = null) use ($mixin) {
$carbonClass = @get_class() ?: Emulator::getClass(new \Exception());
/** @var \Carbon\Carbon|\Cmixin\BusinessDay $self */
$self = $carbonClass::getThisOrToday($self, isset($this) && $this !== $mixin ? $this : null);
//exception by hand need to automate
//array of dates
$ex=array('2020-12-12','2021-12-11');
if (in_array( $self->format('Y-m-d'), $ex)) {$except = true;} else {$except = false; }
return ($self->isWeekday() or $except) && !$self->isHoliday();
};
}
from business-day.
If you modify code on vendor, you'll lose it next time someone will run composer update
, and/or on deploy.
Side note, this if-else is strictly equivalent to:
$except = in_array($self->format('Y-m-d'), config('global.extraworkdays'));
from business-day.
Why not just add holidays the normal way following the documentation example?
https://github.com/kylekatarnls/business-day#setholidays
i couldnt find here method for setting a saturday as business day...
from business-day.
Yes I first believed you were cancelling holidays which is possible, but the isWeekday
is based on $weekendDays
in Carbon
class which is fixed for every week. So short answer:
With the current version of business-day, you can't do that.
You have to add exception in you application code (not the vendor directory code), you should consider the vendor directory as read-only. Else you'll get so many troubles when deploying your app in different environments, working with teams, updating dependencies...
But a really correct way to handle it is to implement an option in the business-day library (via a pull-request here, not modifying files on your side) so it can call a custom method instead of isWeekday()
and then you would be able to customize what is a weekday in your business using a closure.
from business-day.
Thanks for reply!
Ok, i will put a pull-request here, my little modification could be implemented anyway?
from business-day.
No sorry, actually it can't, business-day works well in any framework or PHP application but config()
is a Laravel function. If you add this everywhere business-day is used, you'll break the app of many users having business-day running on non-Laravel applications.
from business-day.
Follow-up in #55.
from business-day.
Related Issues (20)
- Problem with polish holidays HOT 1
- Unknown holiday name in pl HOT 2
- if Sunday then next Tuesday does not work as expected HOT 1
- Bug in italian calculation HOT 1
- Programatically get a list of available regions HOT 1
- Cannot get expression to work properly HOT 4
- Relative logic not working on January 1st HOT 4
- Add Juneteenth to US national holidays HOT 3
- Getting a list of holidays in parsable carbon format HOT 1
- The demo is broken HOT 1
- Possible to add alternative holiday name of the same id? HOT 1
- Request for update: south africa (ZA) holidays
- Undefined method parse HOT 4
- How can I make a day of the week a non-business day? HOT 1
- Business days are not accurate for some countries HOT 1
- Incorrect public holiday for South Africa HOT 1
- Find out if it's a public holiday but still open
- Prayer day is no longer a holiday in Denmark HOT 1
- Carbon 3: Method diffInBusinessdays does not exist HOT 2
- No Indonesian Holidays? 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 business-day.