PHPackages                             sambakon/chrono - 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. sambakon/chrono

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

sambakon/chrono
===============

A PHP utility for date manipulation and formatting

2.2.5(10mo ago)026MITPHPPHP ^8.0CI passing

Since Jul 3Pushed 10mo agoCompare

[ Source](https://github.com/samuelbakon/Chrono)[ Packagist](https://packagist.org/packages/sambakon/chrono)[ RSS](/packages/sambakon-chrono/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (4)Versions (11)Used By (0)

Chrono
======

[](#chrono)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/92c68db7976d7f0780d192563c3904691e85c0a20b1919b6968e6130ce653538/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73616d75656c62616b6f6e2f6368726f6e6f)](https://www.php.net/)[![GitHub Workflow Status](https://camo.githubusercontent.com/d8bb0abb42ff9a221f23bb750cf0834e3b0dd98d485fb3625dc212d29152461c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73616d75656c62616b6f6e2f6368726f6e6f2f7068702e796d6c3f6272616e63683d6d61696e)](https://github.com/samuelbakon/chrono/actions)[![Codecov](https://camo.githubusercontent.com/27e99d3c5b966b3bdb180b3cfb05a1b1b05d640e066eb2a18f6d6b20c568b872/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f73616d75656c62616b6f6e2f6368726f6e6f)](https://codecov.io/gh/samuelbakon/chrono)[![Total Downloads](https://camo.githubusercontent.com/5019d907a6fa8b90ebbe6a54d4274201b62899417edc071b57c06fa101a4ae43/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616d75656c62616b6f6e2f6368726f6e6f)](https://packagist.org/packages/samuelbakon/chrono)

If you're looking for a full-featured PHP date library, I recommend [Carbon](https://carbon.nesbot.com/).

This project is more of a utility library for recurring needs in my projects over time.

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

[](#installation)

Use Composer to install the package :

```
composer require samuelbakon/chrono
```

Migration depuis DateUtil (v1.x vers v2.x)
------------------------------------------

[](#migration-depuis-dateutil-v1x-vers-v2x)

If you're migrating from an older version that used the `DateUtil` class, here's how to update your code :

### Old method (DateUtil) :

[](#old-method-dateutil-)

```
## Recommended Usage (Static Methods)

All Chrono methods are available statically, which is the recommended way to use the library:

```php
use SamBakon\Chrono\Chrono;

// Create and format dates
$date = Chrono::getDate('2023-06-15');
$formatted = Chrono::getDateAsString($date, 'Y-m-d');

// Date calculations
$newDate = Chrono::addDaysToDate($date, 5);
$diff = Chrono::getDateDayDif($date1, $date2);

// Date ranges
$dates = Chrono::getDatesFromRange('2023-06-01', '2023-06-15');
```

### Alternative (Instance Methods)

[](#alternative-instance-methods)

While static usage is preferred, you can also create an instance of Chrono if needed:

```
use SamBakon\Chrono\Chrono;

$chrono = new Chrono();
$date = $chrono->getDate('2023-06-15');
$formatted = $chrono->getDateAsString($date, 'Y-m-d');
```

### Main changes :

[](#main-changes-)

1. Methods have been distributed into specialized classes :

    - `ChronoComputer` : Math operations on dates
    - `ChronoCalendar` : Calendar operations
    - `ChronoPeriod` : Interval management
    - `ChronoCasting` : Conversion and formatting
2. Better method name consistency and return types
3. Better error handling and edge case management
4. More complete documentation and updated examples

Usage
-----

[](#usage)

### Basic usage

[](#basic-usage)

All functionalities are available through static methods of the `Chrono` class:

```
use SamBakon\Chrono\Chrono;

// Create a date
$date = Chrono::getDate('2023-06-15 14:30:00');

// Add days to a date
$newDate = Chrono::addDaysToDate($date, 5);
echo $newDate->format('Y-m-d H:i:s'); // 2023-06-20 14:30:00

// Calculer la différence en minutes entre deux dates
$date1 = new DateTime('2023-06-15 10:00:00');
$date2 = new DateTime('2023-06-15 14:30:00');
$minutesDiff = ChronoComputer::getMinuteDateDif($date1, $date2);
echo "Différence: $minutesDiff minutes"; // 270 minutes

// Convertir des unités de temps
$hours = ChronoComputer::convertMinutesToHours(90); // 1.5
$minutes = ChronoComputer::convertHoursToMinutes(2); // 120

// Obtenir le temps écoulé depuis une date (format lisible)
$lastSeen = new DateTime('2023-06-10 14:30:00');
echo ChronoComputer::lastSeenHelp($lastSeen); // "3 Days" (if today is 13/06/2023)
```

### Calendar operations

[](#calendar-operations)

```
// Get the first day of the week for a given date
$date = Chrono::getDate('2023-06-15'); // A Thursday
$monday = Chrono::getFirstDayOfTheWeekFromDate($date);
echo $monday->format('Y-m-d'); // 2023-06-12 (Monday)

// Formater une date
$formattedDate = ChronoCalendar::formatDateDay($date);
echo $formattedDate; // 15/06/2023

// Obtenir le jour de la semaine
$dayOfWeek = ChronoCalendar::getDayOfWeek($date);
echo $dayOfWeek; // "THURSDAY"

// Obtenir le nom du mois à partir de sa position
echo ChronoCalendar::getMonthFromPosition(6); // "JUN"
```

### Interval management

[](#interval-management)

```
// Get the interval of today (from midnight to 23:59:59)
$today = Chrono::getIntervalOfToday();
$start = $today['start']->format('Y-m-d H:i:s');
$end = $today['end']->format('Y-m-d H:i:s');
echo "Today from $start to $end";

// Get all dates between two dates
$startDate = '2023-06-01';
$endDate = '2023-06-03';
$dates = ChronoPeriod::getDatesFromRange($startDate, $endDate);
// Returns ['2023-06-01', '2023-06-02', '2023-06-03']

// Ajuster un intervalle de dates
$interval = ChronoPeriod::adjustFilterInterval(
    new DateTime('2023-06-01'),
    new DateTime('2023-06-15')
);
```

### Conversion and formatting

[](#conversion-and-formatting)

```
// Convert a timestamp to a DateTime object
$date = Chrono::timeToDate(1686844800);
echo $date->format('Y-m-d'); // 2023-06-15

// Create a DateTime object from a string
$date = Chrono::getDate('2023-06-15');

// Format a date
$formatted = Chrono::getDateAsString($date, 'Y/m/d');
echo $formatted; // 2023/06/15

// Check if a date is valid
$isValid = ChronoCasting::isValidDate('2023-12-31'); // true

// Convert an abbreviated day to its full name
$fullDay = ChronoCasting::parseDay('Mon'); // "Monday"
```

Main features
-------------

[](#main-features)

- **ChronoComputer**: Date calculations and mathematical operations
- **ChronoCalendar**: Calendar operations (weeks, months, years)
- **ChronoPeriod**: Interval management and date ranges
- **ChronoCasting**: Conversion between formats and typing of dates
- Compatible with native PHP DateTime objects
- Strict typing and complete documentation
- High test coverage
- Respect of PSR-12 code standards

Configuration requirements
--------------------------

[](#configuration-requirements)

- PHP 7.4 or higher
- PHP DateTime extension enabled

Licence
-------

[](#licence)

This project is under the MIT license. See the [LICENSE](LICENSE) file for more details.

API Documentation
-----------------

[](#api-documentation)

For a complete documentation of all methods, consult the source code or generate PHPDoc documentation.

Contribution
------------

[](#contribution)

Contributions are welcome! Before submitting a pull request, please :

1. Create an issue to discuss the proposed change
2. Create a branch for your feature (`feature/my-new-feature`)
3. Run the tests and make sure they pass ```
    composer test
    ```
4. Check the code quality : ```
    # Check code style
    composer check-style

    # Run static analysis
    composer static-analysis

    # Check code coverage (must be > 80%)
    composer test-coverage
    ```
5. Update the documentation if necessary
6. Submit a pull request

### Development environment

[](#development-environment)

To configure your development environment :

1. Clone the repository :

    ```
    git clone https://github.com/yourusername/Chrono.git
    cd Chrono
    ```
2. Install dependencies :

    ```
    composer install
    ```
3. Run tests :

    ```
    composer test
    ```

Changelog
---------

[](#changelog)

Consult the [CHANGELOG.md](CHANGELOG.md) for a list of recent changes.

Development
-----------

[](#development)

### Run tests

[](#run-tests)

```
composer test
```

### Check code quality

[](#check-code-quality)

```
composer check-style
composer static-analysis
```

Author
------

[](#author)

- [Samuel Bakon (Samy)](https://samuel-bakon.com)

---

Developed with ❤️ And 🤖

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance54

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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 ~1 days

Total

10

Last Release

306d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a64bcce84e84d22d823156d0c6818ed95a66d76006d27726dafcd2361476c88?d=identicon)[Mr S](/maintainers/Mr%20S)

---

Top Contributors

[![samuelbakon](https://avatars.githubusercontent.com/u/30466078?v=4)](https://github.com/samuelbakon "samuelbakon (13 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sambakon-chrono/health.svg)

```
[![Health](https://phpackages.com/badges/sambakon-chrono/health.svg)](https://phpackages.com/packages/sambakon-chrono)
```

###  Alternatives

[paragi/php-websocket-client

Websocket client

14322.8k](/packages/paragi-php-websocket-client)

PHPackages © 2026

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