Neuron-PHP

IClock

Interface for time/clock operations abstraction.

Provides a testable abstraction over time-dependent operations. Implementations can be real system clock for production or frozen/mock clocks for testing.

Table of Contents

Methods

date()  : string
Format a timestamp as a date string
microtime()  : string|float
Get current timestamp with microseconds
now()  : DateTimeImmutable
Get current DateTime object
sleep()  : void
Sleep for specified seconds
time()  : int
Get current Unix timestamp
usleep()  : void
Sleep for specified microseconds

Methods

date()

Format a timestamp as a date string

public date(string $format[, int|null $timestamp = null ]) : string
Parameters
$format : string

Date format string

$timestamp : int|null = null

Unix timestamp (null = current time)

Return values
string

Formatted date string

microtime()

Get current timestamp with microseconds

public microtime([bool $asFloat = false ]) : string|float
Parameters
$asFloat : bool = false

If true, returns float; otherwise returns string

Return values
string|float

Timestamp with microseconds

now()

Get current DateTime object

public now() : DateTimeImmutable
Return values
DateTimeImmutable

Current date/time

sleep()

Sleep for specified seconds

public sleep(int $seconds) : void
Parameters
$seconds : int

Number of seconds to sleep

time()

Get current Unix timestamp

public time() : int
Return values
int

Current timestamp in seconds since Unix epoch

usleep()

Sleep for specified microseconds

public usleep(int $microseconds) : void
Parameters
$microseconds : int

Number of microseconds to sleep


        
On this page

Search results