navarr/periodically-advancing-clock

An implementation of PSR-20 that advances with each call

v1.0.0 2022-11-26 18:56 UTC

This package is auto-updated.

Last update: 2024-03-26 21:45:31 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License
Tests Code Coverage Mutation score

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

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');