# CakePHP Chronos [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) [![Build Status](https://img.shields.io/travis/cakephp/chronos/master.svg?style=flat-square)](https://travis-ci.org/cakephp/chronos) [![Coverage Status](https://img.shields.io/coveralls/cakephp/chronos/master.svg?style=flat-square)](https://coveralls.io/r/cakephp/chronos?branch=master) [![Total Downloads](https://img.shields.io/packagist/dt/cakephp/chronos.svg?style=flat-square)](https://packagist.org/packages/cakephp/chronos) Chronos aims to be a drop-in replacement for `nesbot/carbon`. It focuses on providing immutable date/datetime objects. Immutable objects help ensure that datetime objects aren't accidentally modified keeping data more predictable. # Installation Installing with composer: ``` $ composer require cakephp/chronos ``` You can then use Chronos: ```php modify('+2 hours'); // This will keep modifications $date = new Chronos('2015-10-21 16:29:00'); $date = $date->modify('+2 hours'); ``` ## Getting Mutable Objects In the case that you need a mutable instance you can get one: ```php $time = new Chronos('2015-10-21 16:29:00'); $mutable = $time->toMutable(); $date = new Date('2015-10-21'); $mutable = $date->toMutable(); ``` ## Converting Mutable Objects into Immutable ones. If you have a mutable object and want an immutable variant you can do the following: ```php $time = new MutableDateTime('2015-10-21 16:29:00'); $fixed = $time->toImmutable(); $date = new MutableDate('2015-10-21'); $fixed = $date->toImmutable(); ``` # Calendar Dates PHP only offers datetime objects as part of the native extensions. Chronos adds a number of conveniences to the traditional DateTime object and introduces a `Date` object. `Date` instances offer compatibility with the `ChronosInterface`, but have their time & timezone frozen to `00:00:00 UTC`. This makes them ideal when working with calendar dates as the time components will always match. ```php use Cake\Chronos\Date; $today = new Date(); echo $today; // Outputs '2015-10-21' echo $today->modify('+3 hours'); // Outputs '2015-10-21' ``` Like instances of `Chronos`, `Date` objects are also *immutable*. The `MutableDate` class provides a mutable variant of `Date`. # Documentation A more descriptive documentation can be found at [book.cakephp.org/chronos/1.x/en/](https://book.cakephp.org/chronos/1.x/en/). # API Documentation API documentation can be found on [api.cakephp.org/chronos](https://api.cakephp.org/chronos).