PHPackages                             d34dman/consecutive-date - 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. d34dman/consecutive-date

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

d34dman/consecutive-date
========================

A utility to find consecutive dates

1.0.0(1y ago)13.8kMITPHP

Since Aug 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/d34dman/consecutive-date)[ Packagist](https://packagist.org/packages/d34dman/consecutive-date)[ RSS](/packages/d34dman-consecutive-date/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Consecutive Date
================

[](#consecutive-date)

A PHP library for finding and counting consecutive dates in a sequence. This library provides a simple and efficient way to determine consecutive date patterns, useful for tracking streaks, daily logins, or any sequential date-based calculations.

Features
--------

[](#features)

- Count consecutive dates backwards from a given date
- Count consecutive dates forwards from a given date
- Support for custom date formats
- Works with both DateTime objects and date strings
- Zero dependencies
- Type-safe implementation
- PSR-4 compliant

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require d34dman/consecutive-date
```

Usage
-----

[](#usage)

### Basic Usage with DateTime Objects

[](#basic-usage-with-datetime-objects)

```
use D34dman\ConsecutiveDate\ConsecutiveDate;

// Create a list of DateTime objects
$dateList = [
    new DateTime("2024-03-15"),
    new DateTime("2024-03-14"),
    new DateTime("2024-03-13"),
    new DateTime("2024-03-12"),
    new DateTime("2024-03-10"), // Note the gap here
];

// Count consecutive days backwards from a specific date
$currentDate = new DateTime("2024-03-15");
$consecutiveDays = ConsecutiveDate::countPastDays($currentDate, $dateList, "Y-m-d");
// Result: 4 (March 15, 14, 13, 12)

// Count consecutive days forwards
$startDate = new DateTime("2024-03-12");
$consecutiveDays = ConsecutiveDate::countFutureDays($startDate, $dateList, "Y-m-d");
// Result: 4 (March 12, 13, 14, 15)
```

### Using String Dates

[](#using-string-dates)

```
use D34dman\ConsecutiveDate\ConsecutiveDateStrings;

// Array of date strings
$dateStrings = [
    "2024-03-15",
    "2024-03-14",
    "2024-03-13",
    "2024-03-12"
];

$currentDate = new DateTime("2024-03-15");
$consecutiveDays = ConsecutiveDateStrings::countPastDays($currentDate, $dateStrings, "Y-m-d");
// Result: 4
```

### Custom Date Formats

[](#custom-date-formats)

```
// Using different date format
$dateStrings = [
    "15/03/2024",
    "14/03/2024",
    "13/03/2024"
];

$currentDate = new DateTime("15/03/2024");
$consecutiveDays = ConsecutiveDateStrings::countPastDays($currentDate, $dateStrings, "d/m/Y");
// Result: 3
```

API Reference
-------------

[](#api-reference)

### ConsecutiveDate Class

[](#consecutivedate-class)

#### `countPastDays(DateTimeInterface $date, array $list, string $date_format): int`

[](#countpastdaysdatetimeinterface-date-array-list-string-date_format-int)

Counts consecutive days backwards from the given date.

- `$date`: The reference date to start counting from
- `$list`: Array of DateTime objects
- `$date_format`: Format string for date comparison (e.g., "Y-m-d")

#### `countFutureDays(DateTimeInterface $date, array $list, string $date_format): int`

[](#countfuturedaysdatetimeinterface-date-array-list-string-date_format-int)

Counts consecutive days forwards from the given date.

- Parameters are same as `countPastDays()`

### ConsecutiveDateStrings Class

[](#consecutivedatestrings-class)

Has the same methods as `ConsecutiveDate` but works with string dates instead of DateTime objects.

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Author
------

[](#author)

- **Shibin Das** - [d34dman](https://github.com/d34dman)
- Email:

Support
-------

[](#support)

If you encounter any problems or have suggestions, please [open an issue](https://github.com/d34dman/consecutive-date/issues) on GitHub.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance40

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

625d ago

### Community

Maintainers

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

---

Top Contributors

[![d34dman](https://avatars.githubusercontent.com/u/1006481?v=4)](https://github.com/d34dman "d34dman (3 commits)")

### Embed Badge

![Health badge](/badges/d34dman-consecutive-date/health.svg)

```
[![Health](https://phpackages.com/badges/d34dman-consecutive-date/health.svg)](https://phpackages.com/packages/d34dman-consecutive-date)
```

PHPackages © 2026

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