Download the PHP package beste/clock without Composer
On this page you can find all versions of the php package beste/clock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package clock
Clock
A collection of PSR-20 Clock implementations.
Table of Contents
- Installation
- Clocks
SystemClock
- Time, as your computer (k)nows itLocalizedClock
- A clock in a(nother) time zoneUTCClock
- The clock that you should™ useFrozenClock
- A clock that stopped moving (perfect for tests)MinuteClock
- Who cares about seconds or even less?WrappingClock
- Allows wrapping a non-clock with anow()
method in a clock
- Running Tests
Installation
Clocks
SystemClock
A System Clock will return a time just as if you would use new DateTimeImmutable()
. The time zone of the returned
value is determined by the clock's environment, for example by the time zone that has been configured in your
application, by a previously used date_default_timezone_set()
or by the value of date.timezone
in the
php.ini
. If none of these are explicitly set, it uses the UTC
timezone.
LocalizedClock
A localized clock is aware of the time zone in which it is located. While the time zone of the SystemClock
is
determined from the environment (your PHP configuration), this clock uses the time zone that you initialize it with.
UTCClock
UTC
is the abbreviation for Coordinated Universal Time
and a special kind of time zone that is not affected by daylight saving time. It is commonly used for the communication
of time across different systems (e.g. between your PHP application and a database, or between a backend
and a frontend). An UTCClock
instance behaves exactly the same as an instance of LocalizedClock::in('UTC')
.
FrozenClock
A frozen clock doesn't move - the time we set it with will stay the same... unless we change it. That makes the frozen clock perfect for testing the behaviour of your time-based use cases, for example in Unit Tests.
MinuteClock
In some cases, microseconds, milliseconds, or even seconds are too precise for some use cases - sometimes it's just enough if something happened in the same minute. Using the minute
WrappingClock
If you already have an object with a now()
method returning a DateTimeImmutable
object, you can wrap it
in a WrappingClock
to make it a "real" Clock.
as a "real" clock.