konecnyjakub/clock 问题修复 & 功能扩展

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

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

konecnyjakub/clock

最新稳定版本:1.1.0

Composer 安装命令:

composer require konecnyjakub/clock

包简介

Collection of PSR-20 clocks

README 文档

README

Total Downloads Latest Stable Version build status coverage report License

Collection of PSR-20 clocks

Installation

The best way to install Clock is via Composer. Just add konecnyjakub/clock to your dependencies.

Usage

System clock

This clock returns current time. It uses default timezone in PHP.

<?php
declare(strict_types=1);

use DateTimeZone;
use Konecnyjakub\Clock\SystemClock;

(new SystemClock())->now();

Local clock

This clock returns current time in the specified time zone.

<?php
declare(strict_types=1);

use DateTimeZone;
use Konecnyjakub\Clock\LocalClock;

(new LocalClock(new DateTimeZone("Europe/Prague")))->now();

Frozen clock

This clock always returns set time which makes it useful for tests.

<?php
declare(strict_types=1);

use DateTimeImmutable;
use Konecnyjakub\Clock\FrozenClock;

(new FrozenClock(new DateTimeImmutable("1970-01-01")))->now();

If you need different values on subsequent calls, you can use FrozenClocksCollection. It returns the values in order which they were passed in or throws an exception if all values were already returned (each value is returned only 1 time). Example:

<?php
declare(strict_types=1);

use DateTimeImmutable;
use Konecnyjakub\Clock\FrozenClocksCollection;

$dt1 = new DateTimeImmutable("2025-01-01");
$dt2 = new DateTimeImmutable("2025-02-01");
$clock = new FrozenClocksCollection($dt1, $dt2);
$clock->now(); // returns $dt1
$clock->now(); // returns $dt2
$clock->now(); // throws an exception

UTC clock

This clock return current time in UTC.

<?php
declare(strict_types=1);

use DateTimeImmutable;
use Konecnyjakub\Clock\UTCClock;

(new UTCClock())->now();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2024-09-15