PHPackages                             rovangju/carbon-nbd - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rovangju/carbon-nbd

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rovangju/carbon-nbd
===================

Carbon DateTime extension to calculate the "next business day"

2.0.0(5y ago)2125.4k↓26.7%3[1 issues](https://github.com/rovangju/carbon-nbd/issues)GPLv2PHPPHP &gt;=7.1.0CI failing

Since Jun 27Pushed 5y ago3 watchersCompare

[ Source](https://github.com/rovangju/carbon-nbd)[ Packagist](https://packagist.org/packages/rovangju/carbon-nbd)[ RSS](/packages/rovangju-carbon-nbd/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (6)Used By (0)

Carbon Wrapper: Next Business Day (NBD)
=======================================

[](#carbon-wrapper-next-business-day-nbd)

[![Build Status](https://camo.githubusercontent.com/8aec5d551a20fe6340a99b9357f4a4fd3248b5fb3684b5164375c542cf5d4854/68747470733a2f2f7472617669732d63692e6f72672f726f76616e676a752f636172626f6e2d6e62642e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rovangju/carbon-nbd)

---

Have some business logic that requires a somewhat complicated calculation for deadlines or effective dates that need to be modified based on holidays, weekends or special dates? This wrapper for the PHP [Carbon project](https://github.com/briannesbitt/Carbon/) (a DateTime extension itself) is for you!

Overview
--------

[](#overview)

The basic principal for this utility is to perform date based logic to determine the "next business day" for a provided date. There are various ways to layer in complexity to supplement holidays and deadlines.

The meat and potatoes functionality is provided by the `nbd(Carbon $c)` method. The method will perform it's checking routine by checking the various criteria and incrementing the day by one in a loop. The `nbd()` method will return an updated `Carbon::` object with the date set to the appropriate business day.

**Please note: This is for date logic only**.

### Basic usage

[](#basic-usage)

```
use CarbonExt\NBD\Calculator;
use CarbonExt\NBD\CoreCallbacks C;
use Carbon\Carbon;

$nbd = new Calculator();

/* Date to find the next business day for */
$dt = new Carbon('2014-01-01');

/* Cherry pick special dates */
$nbd->addExclusion(new Carbon('2014-01-02'));
var_dump($nbd->nbd($dt)); /* Carbon obj: 2014-01-03 */
```

### Callback support

[](#callback-support)

```
/* Custom exclusion callbacks for layering in complexity */
$nbd->addCallback(C::noWeekends());
$nbd->addCallback(C::ignoreDaysOfWeek(array(4))); /* No Fridays, uses Carbon's 0-based offsets */

/* All callback functions must accept a Carbon object and return a bool value */
$cfn = function(Carbon $dt) {
	return ($dt->day % 2 == 0);
}

$nbd->addCallback($cfn); /* Only on even days of the month */
```

### Deadline support

[](#deadline-support)

Say you want to allow payments made *today, before 3:00pm* effective today. If the payment was submitted *after* 3:00pm, it is not effective until the next business day...

**NOTE: Deadlines are ONLY effective based on hour logic; the date passed into setDeadline() is unregarded!**

```
$nbd->setDeadline(new Carbon('3:00pm'));

$nbd->nbd(new Carbon('2014-01-01 2:59:59pm')); /* Carbon obj: 2014-01-01 00:00:00 */
$nbd->nbd(new Carbon('2014-01-01 3:00:01pm')); /* Carbon obj: 2014-01-02 00:00:00 */
```

---

A more complete use case via extension...
-----------------------------------------

[](#a-more-complete-use-case-via-extension)

```
use CarbonExt\NBD\Calculator;
use CarbonExt\NBD\CoreCallbacks as C;
use Carbon\Carbon;

class BusinessDayCalc extends Calculator {

	protected $observedHolidays = array(
		'January 1st', /* New years */
		'July 4th', /* Independence Day */
		'November 28th', /* Thanksgiving */
		'December 25th', /* Christmas */
	);

	public function __construct() {

		$this->addCallback(C::noWeekends());

        $observed = array();

        /* Use ignoreRecurring strategy to ignore recurring month-day combos */
		foreach ($this->observedHolidays as $dt) {
			$observed[] = new Carbon($dt);
		}

		$this->addCallback(C::ignoreRecurring($observed));

		/* Use ignoreNDOW strategy to ignore complex, verbal-oriented exceptions */
		/* Ignore Memorial Day: Last Monday of May */
		$this->addCallback(C::ignoreNDOW(5, -1, 1));

		/* Ignore Labor Day: First Monday of September */
		$this->addCallback(C::ignoreNDOW(9, 1, 1));
	}
}

$nbd = new BusinessDayCalc();
/* Now all your business use-case rules are automatically built in */
```

---

Contributing
------------

[](#contributing)

Please follow the [Git Flow](https://github.com/nvie/gitflow) conventions. Proposals should be performed against develop or a feature/bugfix/support branch to be merged in by the maintainer.

Releases/versioning semantics follow the [Semantic Versioning](http://semver.org) 2.0.x guidelines. Minute adjustments (e.g.: changes to this README.md) may or may not result in a new version tag, depending on the nature of the change.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1150 days

Total

3

Last Release

2036d ago

Major Versions

1.1.0 → 2.0.02020-10-14

PHP version history (2 changes)1.0.0+1PHP &gt;=5.3.0

2.0.0PHP &gt;=7.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b0c99899a1fb5cb78591514949801e1dc8ad4d3c64eaf5f405dd78bb27c76ce?d=identicon)[rovangju](/maintainers/rovangju)

---

Top Contributors

[![rovangju](https://avatars.githubusercontent.com/u/780280?v=4)](https://github.com/rovangju "rovangju (15 commits)")

---

Tags

datetimecarbonBusiness Daynext-business-day

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rovangju-carbon-nbd/health.svg)

```
[![Health](https://phpackages.com/badges/rovangju-carbon-nbd/health.svg)](https://phpackages.com/packages/rovangju-carbon-nbd)
```

###  Alternatives

[morilog/jalali

This Package helps developers to easily work with Jalali (Shamsi or Iranian) dates in PHP applications, based on Jalali (Shamsi) DateTime class.

9201.2M45](/packages/morilog-jalali)[kylekatarnls/laravel-carbon-2

Carbon 2 adapter for Laravel

631.2M1](/packages/kylekatarnls-laravel-carbon-2)[geoffreyrose/us-holidays

US Holidays Wrapper for the Carbon DateTime Library.

62717.0k2](/packages/geoffreyrose-us-holidays)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
