Download the PHP package firehed/clock without Composer

On this page you can find all versions of the php package firehed/clock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package clock

Clock

A PSR-20 Clock implementation, with time configuration and movement support for use in unit tests.

Test Static analysis Lint codecov

Installation

Usage

Generally speaking, ClockInterface is only useful when paired with Dependency Injection. This allows unit tests to provide a test clock set to a specific point in time, where the actual application is wired to use a wall clock and follows real time.

Wall Clock

A wall clock will return the current system time any time ->now() is called. It advances normally and behaves identically to calling time() or new DateTimeImmutable() directly would.

This is what you should use in actual application code.

[!IMPORTANT] A clock in "wall clock" mode cannot be moved, and will throw an exception if you attempt to do so.

Test Clock

A test clock will return a specified time, and can be manually moved. It will not advance automatically as actual wall time progresses (e.g. is unaffected by sleep(), etc). This is intended for use in test cases, such as:

Basically, if you'd normally have to use sleep() to check something, you can instead move the test clock by a specificed amount or to a specified time and continue the test case as if that time had passed. This can result in tests that run faster and more reliably, without having to fuss with "give or take a second" logic.

The behavior of $timeOrOffset and $otherTimeOrOffset is as follows:

Type __construct Behavior moveTo() behavior
DateTimeInterface The clock will be fixed to the specified time The clock will move to the specified time
DateInterval The clock will be fixed to the system time when construct is called, plus the offset The clock will advance by the offset from its initial fixed time
string that starts with P The string will be parsed as a DateInterval and behave as above Same
string The clock will be fixed to an equivalent of strtotime(string) Same
int or float The value will be interpreted as a Unix timestamp and fixed to that time Same
Anything else A TypeError will be thrown Same

[!WARNING] float values can and often do lose precision at timestamps near the current time. If your test needs sub-second behavior, prefer any of the more-specific formats.

Unixtime strings avoid floating point precision issues. These are @ followed by the timestamp; e.g. '@1234567890.987654'

The library does not make guarantees about subsequent calls to ->now() on a test clock being the same or different DateTimeImmutable instances. However, they are guaranteed to be in reference to the same point in time.

[!TIP] If you only care about relative movement, a test clock can be set up as new Clock('now'). You may also use only small values near the Unix epoch (e.g. 0, 20); if your application uses ClockInterface consistently it should still work, and run as if the current time was in 1970.

Moving the clock backwards

Relative time changes always use DateTimeImmutable->add() or the equivalent internally.

To move the clock backwards:

Time Zones

This library does not currently aim to handle any time zone specifics, and will default to the system configuration. If your needs include specific behavior regarding time zones, be sure to provide values that include time zone information.

Contributing

Please report any bugs or feature requests on GitHub. Be aware that this is considered mostly feature-complete, so feature requests may be declined.


All versions of clock with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
psr/clock Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package firehed/clock contains the following files

Loading the files please wait ....