Download the PHP package cakephp/chronos without Composer
On this page you can find all versions of the php package cakephp/chronos. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cakephp/chronos
More information about cakephp/chronos
Files in cakephp/chronos
Package chronos
Short Description A simple API extension for DateTime.
License MIT
Homepage https://cakephp.org
Informations about the package chronos
CakePHP Chronos
Chronos 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:
For details on the (minimum/maximum) PHP version see version map.
Usage
Differences with nesbot/carbon
Chronos was originally compatible with Carbon but has diverged and no longer extends the PHP DateTime and DateTimeImmutable classes.
Immutable Object Changes
Immutable objects have a number of advantages:
- Using immutable objects is always free of side-effects.
- Dates and times don't accidentally change underneath other parts of your code.
With those benefits in mind, there are a few things you need to keep in mind when modifying immutable objects:
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 ChronosDate object. ChronosDate instances their time frozen to 00:00:00 and the timezone
set to the server default timezone. This makes them ideal when working with
calendar dates as the time components will always match.
Like instances of Chronos, ChronosDate objects are also immutable.
Time-only Values
When you need to work with just times (without dates), use ChronosTime:
ChronosTime is useful for recurring schedules, business hours, or any scenario
where the date is irrelevant.
Testing with Chronos
Chronos provides setTestNow() to freeze time during testing:
PSR-20 Clock Interface
For dependency injection, use ClockFactory which implements PSR-20:
Documentation
A more descriptive documentation can be found at book.cakephp.org/chronos/3/.
API Documentation
API documentation can be found on api.cakephp.org/chronos.