https://github.com/morebec/orkestra-datetime
[READ ONLY] Extension of CakePHP/Chronos that adds utility functions around DateTime manipulation.
https://github.com/morebec/orkestra-datetime
chronos datetime orkestra php
Last synced: 10 months ago
JSON representation
[READ ONLY] Extension of CakePHP/Chronos that adds utility functions around DateTime manipulation.
- Host: GitHub
- URL: https://github.com/morebec/orkestra-datetime
- Owner: Morebec
- License: apache-2.0
- Created: 2021-04-21T00:52:27.000Z (almost 5 years ago)
- Default Branch: 2.x
- Last Pushed: 2023-03-31T18:45:53.000Z (almost 3 years ago)
- Last Synced: 2025-03-02T06:49:09.680Z (11 months ago)
- Topics: chronos, datetime, orkestra, php
- Language: PHP
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# DateTime
The Orkestra DateTime Component builds on top of [cakephp/chronos](https://github.com/cakephp/chronos) which itself builds on top of
[nesbot/carbon](https://github.com/nesbot/carbon) in order to bring immutability to dates and times as the default.
It provides the concept of a `ClockInterface` to be used in projects to get the time as an infrastructure concern
instead of directly accessing time as well as providing Date(Time)Range implementations.
## Installation
```shell
composer require morebec/orkestra-orkestra-datetime
```
Then ensure the composer autoloader is imported:
```php
now());
```
## Usage
### `ClockInterface`
The clock interface is used in order to centralize the location where the current date/time is fetched.
In essence, doing things like `DateTime::now()` in arbitrary locations of the code makes it harder to test, and manipulate.
Being an infrastructure related concept, it makes more sense to obtain the time from a Clock than being able to access
it from anywhere.
This can allow to test the system in the past or future.
Here are the implementations of the `ClockInterface`:
- `SystemClock` Implementation of the system clock based on the time of the system.
- `FixedClock` Implementation of clock always returning the same fixed date time, to be used in unit tests for better control of time.
- `OffsetClock` Clock that returns the date time from a specific defined offset at creation as if it were the current time. This is useful when we have to reverse in time or fast-forward in the future but still keep the clock running as the actual time passes.
For more information on the available functions of `Date` and `DateTime`, please refer to the documentation of [cakephp/chronos](https://github.com/cakephp/chronos).