https://github.com/code16/carbon-business-days
A simple class for business days counting
https://github.com/code16/carbon-business-days
carbon php-library
Last synced: 10 months ago
JSON representation
A simple class for business days counting
- Host: GitHub
- URL: https://github.com/code16/carbon-business-days
- Owner: code16
- Created: 2018-05-18T08:09:24.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T09:57:44.000Z (almost 2 years ago)
- Last Synced: 2025-05-24T11:23:29.883Z (10 months ago)
- Topics: carbon, php-library
- Language: PHP
- Size: 11.7 KB
- Stars: 54
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# A simple business days calculator
This package aims to count business working days between two [Carbon](https://github.com/briannesbitt/Carbon) dates.
## Usage
```php
$date = new BusinessDays();
// Set holidays (2018-1-1 is a Monday)
$date->addHoliday(Carbon::createFromDate(2018, 1, 1));
// Should return 9
$days = $date->daysBetween(
Carbon::createFromDate(2018, 1, 1),
Carbon::createFromDate(2018, 1, 15)
);
// Set a closed period (whole 2nd week)
$date->addClosedPeriod(
Carbon::createFromDate(2018, 1, 8),
Carbon::createFromDate(2018, 1, 12)
);
// Should return 5
$days = $date->daysBetween(
Carbon::createFromDate(2018, 1, 1),
Carbon::createFromDate(2018, 1, 15)
);
```
Default for weekend days are saturdays and sundays, but it can be configured:
```php
$date->setWeekendDays([Carbon::SUNDAY, Carbon::MONDAY]);
```
You can also add or subtract days from a given date:
```php
$newDate = $date->addDaysTo(
Carbon::createFromDate(2018, 5, 14),
10
);
$newDate = $date->subDaysFrom(
Carbon::createFromDate(2018, 5, 14),
10
);
```
## Installation
```
composer require code16/carbon-business-days
```
## License
MIT