Skip to content

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.

final class SystemClock implements ClockInterface

ImplementsClockInterface
SourceSupport/Clock/SystemClock.php
MethodDescription
microtime(): floatWall-clock Unix timestamp with microsecond precision.
monotonic(): floatSeconds on a monotonic clock: immune to wall-clock steps, so only ever meaningful as the difference between two readings.
now(): DateTimeImmutableThe current wall-clock time.
unixTimestamp(): intWall-clock Unix timestamp in whole seconds.

public function microtime(): float

Wall-clock Unix timestamp with microsecond precision.

Replaces a direct microtime(true) call.

Returns float

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

public function unixTimestamp(): int

Wall-clock Unix timestamp in whole seconds.

Replaces a direct time() call.

Returns int