kuria / clock
Provides access to current date and time that can be mocked for testing purposes
Installs: 8 223
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
Requires (Dev)
- kuria/dev-meta: ^0.5
This package is auto-updated.
Last update: 2024-12-22 18:13:05 UTC
README
Provides access to current date and time that can be mocked for testing purposes.
Contents
Requirements
- PHP 7.1+
Usage
The Kuria\Clock\Clock
class provides access to current date and time.
Getting current time
Clock::time(): int
- get the current UNIX timestamp
Clock::microtime(): float
- get the current UNIX timestamp with microsecond precision
Clock::dateTime(?\DateTimeZone $timezone = null): \DateTime
- get the current date-time
- uses default time zone if not specified
Clock::dateTimeImmutable(?\DateTimeZone $timezone = null): \DateTimeImmutable
- get the current date-time as an immutable instance
- uses default time zone if not specified
Overriding current time
Clock::override($now): void
- override the current time
$now
can be an UNIX timestamp or an instance ofDateTimeInterface
$now
can include microseconds- this change only affects methods of the
Clock
class
Clock::isOverridden(): bool
- see if the current time is currently overridden
Clock::resume(): void
- resume normal operation after the time has been overridden
- if the time is not currently overridden, this method does nothing
Note
Time overriding is intended only for testing purposes.