navarr/periodically-advancing-clock

PSR-20 的实现,每次调用时都会前进

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

This package is auto-updated.

Last update: 2024-08-26 22:40:12 UTC


README

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

这是一个 PSR-20 的实现,每次调用 ->now() 时都会使时钟前进一个定义好的周期

安装

composer require navarr/periodically-advancing-clock:^1

使用

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