SystemClock
The real clock: ClockInterface::now()/ClockInterface::unixTimestamp()/ ClockInterface::microtime() answer from the system wall clock exactly like new DateTimeImmutable()/time()/microtime(true) always did, and ClockInterface::monotonic() from hrtime(true).
This is what the container binds ClockInterface to by default; nothing here is mockable, which is the point — tests reach for FrozenClock or OffsetClock instead of stubbing this class.
Synopsis
Section titled “Synopsis”final class SystemClock implements ClockInterface
| Implements | ClockInterface |
| Source | Support/Clock/SystemClock.php |
Methods
Section titled “Methods”| Method | Description |
|---|---|
microtime(): float | Wall-clock Unix timestamp with microsecond precision. |
monotonic(): float | Seconds on a monotonic clock: immune to wall-clock steps, so only ever meaningful as the difference between two readings. |
now(): DateTimeImmutable | The current wall-clock time. |
unixTimestamp(): int | Wall-clock Unix timestamp in whole seconds. |
microtime()
Section titled “microtime()”public function microtime(): float
Wall-clock Unix timestamp with microsecond precision.
Replaces a direct microtime(true) call.
Returns float
monotonic()
Section titled “monotonic()”public function monotonic(): float
Seconds on a monotonic clock: immune to wall-clock steps, so only ever meaningful as the difference between two readings.
Replaces a direct hrtime(true) call (or a microtime(true) one used for a duration rather than a point in time).
Returns float
public function now(): DateTimeImmutable
The current wall-clock time.
Returns DateTimeImmutable
unixTimestamp()
Section titled “unixTimestamp()”public function unixTimestamp(): int
Wall-clock Unix timestamp in whole seconds.
Replaces a direct time() call.
Returns int