tobento/service-clock 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tobento/service-clock

最新稳定版本:2.0

Composer 安装命令:

composer require tobento/service-clock

包简介

PSR-20 clocks for PHP applications.

README 文档

README

Providing PSR-20 clocks for PHP applications.

Table of Contents

Getting started

Add the latest version of the clock service project running this command.

composer require tobento/service-clock

Requirements

  • PHP 8.4 or greater

Highlights

  • Framework-agnostic, will work with any project
  • Decoupled design

Documentation

Available Clocks

System Clock

The system clock relies on the current system time. If the timezone parameter is not defined it uses the timezone from the date_default_timezone_get method.

use Tobento\Service\Clock\SystemClock;
use Psr\Clock\ClockInterface;

$clock = new SystemClock();

var_dump($clock instanceof ClockInterface);
// bool(true)

With defined timezone parameter

use Tobento\Service\Clock\SystemClock;
use DateTimeZone;

$clock = new SystemClock(
    timezone: 'UTC'
);

$clock = new SystemClock(
    timezone: new DateTimeZone('Europe/Berlin')
);

Frozen Clock

The frozen clock will always return the same date time, suitable for testing. If the now parameter is not defined it uses the current time of the System Clock.

use Tobento\Service\Clock\FrozenClock;
use Psr\Clock\ClockInterface;

$clock = new FrozenClock();

var_dump($clock instanceof ClockInterface);
// bool(true)

// Modify the clock returning a new instance.
// Will accept all formats supported by DateTimeImmutable::modify()
$clockNew = $clock->modify('+30 seconds');

// With a new timezone returning a new instance.
$clockNew = $clock->withTimeZone(timezone: 'UTC');

With defined now parameter

use Tobento\Service\Clock\FrozenClock;
use Tobento\Service\Clock\SystemClock;
use Psr\Clock\ClockInterface;
use DateTimeImmutable;

$clock = new FrozenClock(
    now: new DateTimeImmutable()
);

// or from another clock:
$clock = new FrozenClock(
    now: new SystemClock()
);

Credits

统计信息

  • 总下载量: 215
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 7
  • 推荐数: 1

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-22