Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ghostwriter/clock
Provides an immutable Clock implementation for PHP
https://github.com/ghostwriter/clock
clock ghostwriter
Last synced: about 1 month ago
JSON representation
Provides an immutable Clock implementation for PHP
- Host: GitHub
- URL: https://github.com/ghostwriter/clock
- Owner: ghostwriter
- License: bsd-3-clause
- Created: 2023-09-28T18:17:14.000Z (about 1 year ago)
- Default Branch: 3.0.x
- Last Pushed: 2024-08-31T15:28:47.000Z (3 months ago)
- Last Synced: 2024-10-03T10:56:55.427Z (about 2 months ago)
- Topics: clock, ghostwriter
- Language: PHP
- Homepage: https://github.com/ghostwriter/clock
- Size: 389 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Clock
[![Automation](https://github.com/ghostwriter/clock/actions/workflows/automation.yml/badge.svg)](https://github.com/ghostwriter/clock/actions/workflows/automation.yml)
[![Supported PHP Version](https://badgen.net/packagist/php/ghostwriter/clock?color=8892bf)](https://www.php.net/supported-versions)
[![GitHub Sponsors](https://img.shields.io/github/sponsors/ghostwriter?label=Sponsor+@ghostwriter/clock&logo=GitHub+Sponsors)](https://github.com/sponsors/ghostwriter)
[![Code Coverage](https://codecov.io/gh/ghostwriter/clock/branch/main/graph/badge.svg)](https://codecov.io/gh/ghostwriter/clock)
[![Type Coverage](https://shepherd.dev/github/ghostwriter/clock/coverage.svg)](https://shepherd.dev/github/ghostwriter/clock)
[![Latest Version on Packagist](https://badgen.net/packagist/v/ghostwriter/clock)](https://packagist.org/packages/ghostwriter/clock)
[![Downloads](https://badgen.net/packagist/dt/ghostwriter/clock?color=blue)](https://packagist.org/packages/ghostwriter/clock)Provides an immutable Clock implementation for PHP
## Installation
You can install the package via composer:
``` bash
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
now(); // DateTimeImmutable
$systemClock->now()->getTimezone()->getName(); // America/Los_Angelesdate_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
``` php
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](./CHANGELOG.md) for more information what has changed recently.
### Security
If you discover any security related issues, please email `[email protected]` or create a [Security Advisory](https://github.com/ghostwriter/clock/security/advisories/new) instead of using the issue tracker.
## License
The BSD-3-Clause. Please see [License File](./LICENSE) for more information.