psr/clock

Common interface for reading the clock.

Maintainers

👁 fig
👁 cseufert

Package info

github.com/php-fig/clock

pkg:composer/psr/clock

Statistics

Installs: 371 888 610

Dependents: 380

Suggesters: 1

Stars: 642

Open Issues: 0

1.0.0 2022-11-25 14:36 UTC

Requires

  • php: ^7.0 || ^8.0

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT e41a24703d4560fd0acb709162f73b8adfc3aa0d

timepsrclocknowpsr-20

This package is auto-updated.

Last update: 2026-05-21 19:59:58 UTC


README

This repository holds the interface for PSR-20.

Note that this is not a clock of its own. It is merely an interface that describes a clock. See the specification for more details.

Installation

composer require psr/clock

Usage

If you need a clock, you can use the interface like this:

<?php

use Psr\Clock\ClockInterface;

class Foo
{
 private ClockInterface $clock;

 public function __construct(ClockInterface $clock)
 {
 $this->clock = $clock;
 }

 public function doSomething()
 {
 /** @var DateTimeImmutable $currentDateAndTime */
 $currentDateAndTime = $this->clock->now();
 // do something useful with that information
 }
}

You can then pick one of the implementations of the interface to get a clock.

If you want to implement the interface, you can require this package and implement Psr\Clock\ClockInterface in your code.

Don't forget to add psr/clock-implementation to your composer.jsons provide-section like this:

{
 "provide": {
 "psr/clock-implementation": "1.0"
 }
}

And please read the specification text for details on the interface.