承接 ghostwriter/clock 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ghostwriter/clock

最新稳定版本:3.0.1

Composer 安装命令:

composer require ghostwriter/clock

包简介

Provides a Clock implementation for PHP

README 文档

README

GitHub Sponsors Automation Supported PHP Version Downloads

Provides an immutable Clock implementation for PHP

Installation

You can install the package via composer:

composer require ghostwriter/clock

Star ⭐️ this repo if you find it useful

You can also star (????) this repo to find it easier later.

Usage

<?php

// Internally uses SystemClock::new(new DateTimeZone(date_default_timezone_get()));

date_default_timezone_set('America/Los_Angeles');
$systemClock = SystemClock::new();
$systemClock->now(); // DateTimeImmutable
$systemClock->now()->getTimezone()->getName(); // America/Los_Angeles

date_default_timezone_set('America/New_York');
$systemClock = SystemClock::new();
$systemClock->now(); // DateTimeImmutable
$systemClock->now()->getTimezone()->getName(); // America/New_York

$localizedClock = LocalizedClock::new();
$localizedClock->now(); // DateTimeImmutable
$localizedClock->now()->getTimezone()->getName(); // UTC

$localizedClock = LocalizedClock::new(new DateTimeZone('Africa/Addis_Ababa'));
$localizedClock->now(); // DateTimeImmutable
$localizedClock->now()->getTimezone()->getName(); // Africa/Addis_Ababa

$frozenClock = FrozenClock::new(new DateTimeImmutable('now', new DateTimeZone('UTC')));
$frozenClock->now(); // DateTimeImmutable
$frozenClock->now()->getTimezone()->getName(); // UTC

API

interface ClockInterface
{
    public function freeze(): FrozenClockInterface;

    public function now(): DateTimeImmutable;
}

interface FrozenClockInterface extends ClockInterface
{
    public static function new(DateTimeImmutable $dateTimeImmutable): self;
}

interface LocalizedClockInterface extends ClockInterface
{
    public static function new(DateTimeZone $dateTimeZone): self;
}

interface SystemClockInterface extends ClockInterface
{
    public static function new(): self;
}

Changelog

Please see CHANGELOG.md for more information what has changed recently.

Security

If you discover any security related issues, please email nathanael.esayeas@protonmail.com or create a Security Advisory instead of using the issue tracker.

License

The BSD-4-Clause. Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-01-04