Skip to content

Commit

Permalink
Merge pull request #12 from alex-patterson-webdev/feature/0.6.0
Browse files Browse the repository at this point in the history
Feature/0.6.0
  • Loading branch information
alex-patterson-webdev committed Apr 11, 2023
2 parents cd8c925 + eac7d3d commit c417315
Show file tree
Hide file tree
Showing 34 changed files with 923 additions and 888 deletions.
1 change: 0 additions & 1 deletion .php-cs-fixer.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ return (new PhpCsFixer\Config())
->setRules($rules)
->setFinder($finder)
->setUsingCache(false);

24 changes: 10 additions & 14 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
build:
nodes:
php74:
environment:
php: 7.4
analysis:
environment:
php: 7.4
project_setup:
override:
- 'true'
tests:
override:
- php-scrutinizer-run
- command: phpcs-run
image: default-bionic
environment:
php: 8.1
project_setup:
override:
- 'true'
tests:
override:
- php-scrutinizer-run
- command: phpcs-run
checks:
php: true
coding_style:
Expand Down
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

## About

The library provides a number of factory interfaces which abstracts the creation of native PHP DateTime classes,
`\DateTime`, `\DateTimeImmutible`, `\DateInterval` and `\DateTimeZone`.
The library provides a number of factory interfaces which abstracts the creation of native PHP DateTime objects and
implementations of the [PSR-20 Clock](https://www.php-fig.org/psr/psr-20/) `ClockInterface`.

## Installation

Expand Down Expand Up @@ -125,6 +125,34 @@ The default implementation of the interface is `Arp\DateTime\DateTimeZoneFactory
// The \DateTimeZone() could not be created
}

### PSR-20 ClockInterface

Using the PSR standards provides implementing projects interoperability between other packages by creating a standard way of accessing
the current time.

The package provides a number of implementations of the [PSR-20 Clock](https://www.php-fig.org/psr/psr-20/) interface.

- `Arp\DateTime\Psr\Clock` A default implementation of `Psr\Clock\ClockInterface` where a desired DateTimeZone can be provided.
- `Arp\DateTime\Psr\SystemClock` An implementation of `Psr\Clock\ClockInterface` that will always provide the current time using the configured system timezone.
- `Arp\DateTime\Psr\FixedClock` An implementation of `Psr\Clock\ClockInterface` that will always return a fixed `\DateTimeImmutable`; which can be useful in testing.

Example usages

use Arp\DateTime\DateTimeImmutableFactory;
use Arp\DateTime\Psr\SystemClock;

// Fetch the current time using the UTC timezone
$clock = new Clock(new DateTimeImmutableFactory(), 'UTC');
$utcTime = $clock->now();

// Fetch the current time using the systems configured timezone
$clock = new SystemClock(new DateTimeImmutableFactory());
$systemTime = $clock->now();

// Calls to FixedClock::now() will always return the same time provided in the constructor
$clock = new FixedClock(new \DateTimeImmutable());
$fixedTime = $clock->now();

## Unit tests

Unit tests can be executed using PHPUnit from the application root directory.
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
"minimum-stability": "dev",
"prefer-stable": true,
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Alex Patterson",
"email": "[email protected]"
}
],
"require" : {
"php" : ">=7.4 || >=8.0"
"php": ">=8.1",
"psr/clock": "^1.0.0"
},
"require-dev": {
"phpspec/prophecy": "^1.15.0",
Expand Down Expand Up @@ -57,5 +59,8 @@
"config": {
"optimize-autoloader": true,
"sort-packages": true
},
"provide": {
"psr/clock-implementation": "1.0"
}
}
Loading

0 comments on commit c417315

Please sign in to comment.