ghostwriter / clock
Provides a Clock implementation for PHP
Fund package maintenance!
ghostwriter
Installs: 693 836
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
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.0
- 1.1.0
- 1.0.0
- dev-dependencies/composer-lock/3d18d86
- dev-dependencies/composer-lock/5a54642
- dev-dependencies/composer-lock/0ca5cb5
- dev-dependencies/composer-lock/6859130
- dev-dependencies/composer-lock/9180a9d
- dev-dependencies/composer-lock/5856da1
- dev-dependencies/composer-lock/12310eb
- dev-dependencies/composer-lock/34a0a48
- dev-dependencies/composer-lock/37ed8d1
- dev-chore/update/infection/ec034e5
- dev-main
This package is auto-updated.
Last update: 2025-02-21 19:51:58 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.