ghostwriter / clock
Provides a Clock implementation for PHP
Fund package maintenance!
3.0.1
2025-01-05 19:26 UTC
Requires
- php: >=8.3
Requires (Dev)
- ghostwriter/coding-standard: dev-main
- ghostwriter/psalm-plugin: dev-main
- 4.0.x-dev
- 3.1.x-dev
- 3.0.x-dev
- 3.0.1
- 3.0.0
- 2.0.x-dev
- 2.0.0
- 1.1.x-dev
- 1.1.0
- 1.0.x-dev
- 1.0.0
- dev-main
- dev-merge-up/4.0.x-into-main
- dev-merge-up/3.0.x-into-3.1.x
- dev-composer-install-ghostwriter-testify
- dev-composer-update
- dev-merge-up/3.1.x-into-4.0.x
- dev-composer-boundwize-structarmed-0.7.6
- dev-composer-boundwize-structarmed-0.7.5
- dev-composer-boundwize-structarmed-0.7.4
- dev-phpunit-configuration
- dev-composer-boundwize-structarmed-0.6.17
- dev-composer-phpunit-phpunit-13.1.11
- dev-composer-boundwize-structarmed-0.6.16
- dev-composer-boundwize-structarmed-0.6.15
- dev-infection-configuration
- dev-composer-boundwize-structarmed-0.6.14
- dev-composer-boundwize-structarmed-0.6.13
- dev-composer-boundwize-structarmed-0.6.10
- dev-composer-boundwize-structarmed-0.6.9
- dev-composer-boundwize-structarmed-0.6.8
- dev-composer-boundwize-structarmed-0.6.6
- dev-composer-boundwize-structarmed-0.6.5
- dev-composer-boundwize-structarmed-0.6.4
- dev-composer-boundwize-structarmed-0.6.3
- dev-composer-boundwize-structarmed-0.6.2
- dev-composer-boundwize-structarmed-0.5.5
- dev-composer-phpunit-phpunit-13.1.10
- dev-composer-boundwize-structarmed-0.5.4
- dev-composer-boundwize-structarmed-0.5.2
- dev-composer-boundwize-structarmed-0.5.1
- dev-composer-phpunit-phpunit-13.1.9
- dev-composer-install-boundwize-structarmed
- dev-composer/update
This package is auto-updated.
Last update: 2026-05-23 15:50:54 UTC
README
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-3-Clause. Please see License File for more information.