Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/navarr/periodically-advancing-clock
An implementation of PSR-20 that advances with each call
https://github.com/navarr/periodically-advancing-clock
Last synced: about 7 hours ago
JSON representation
An implementation of PSR-20 that advances with each call
- Host: GitHub
- URL: https://github.com/navarr/periodically-advancing-clock
- Owner: navarr
- License: mit
- Created: 2021-08-29T02:57:30.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-26T19:00:41.000Z (almost 2 years ago)
- Last Synced: 2024-05-01T19:32:14.633Z (6 months ago)
- Language: PHP
- Size: 13.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Periodically Advancing Clock (PSR-20)
[![Latest Stable Version](http://poser.pugx.org/navarr/periodically-advancing-clock/v)](https://packagist.org/packages/navarr/periodically-advancing-clock)
[![Total Downloads](http://poser.pugx.org/navarr/periodically-advancing-clock/downloads)](https://packagist.org/packages/navarr/periodically-advancing-clock)
[![Latest Unstable Version](http://poser.pugx.org/navarr/periodically-advancing-clock/v/unstable)](https://packagist.org/packages/navarr/periodically-advancing-clock)
[![License](http://poser.pugx.org/navarr/periodically-advancing-clock/license)](https://packagist.org/packages/navarr/periodically-advancing-clock)
![Tests](https://github.com/navarr/periodically-advancing-clock/actions/workflows/commit.yml/badge.svg)
![Code Coverage](https://codecov.io/gh/navarr/periodically-advancing-clock/branch/main/graph/badge.svg?token=BHTKOZZDR3)
[![Mutation score](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fnavarr%2Fperiodically-advancing-clock%2Fmain)](https://dashboard.stryker-mutator.io/reports/github.com/navarr/periodically-advancing-clock/main)This is an implementation of PSR-20 that provides a clock that advances one defined period with each call of `->now()`
## Installation
composer require navarr/periodically-advancing-clock:^1
## Usage
```php
use DateInterval;
use DateTimeImmutable;
use Navarr\PeriodicAdvancement\AdvancingClock;// ...
$date = new DateTimeImmutable('2021-02-20');
$period = new DateInterval('P1M');
$clock = new SpecificTime(startDate: $date, period: $period);// 2021-02-20
echo $clock->now()->format('Y-m-d');// 2021-03-20
echo $clock->now()->format('Y-m-d');
```