定制 konecnyjakub/clock 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱: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
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固