CooperDuration
in package
implements
Stringable
A CASC duration (CASC.md ยง6.8) -- `500ms`, `1h30m`, or `!duration("5m")` -- as a whole number of nanoseconds, the same base unit the Elixir original's `{:duration, nanoseconds}` uses.
The count follows the integer rule (CooperInteger): a native int
when it fits in 64 bits, a CooperInteger beyond. It was once a plain
int, and 300000000d -- about 820 000 years, which the reference
loads without complaint -- was a load error here.
Table of Contents
Interfaces
- Stringable
Properties
- $nanoseconds : int|CooperInteger
- The duration's total length in nanoseconds.
Methods
- __construct() : mixed
- __toString() : string
- The duration in its base unit -- `"500000000ns"` -- which is also valid CASC if fed back in.
- equals() : bool
- toMicroseconds() : int|CooperInteger
- toMilliseconds() : int|CooperInteger
- toSeconds() : float
- divided() : int|CooperInteger
- `$count` divided by `$divisor`, truncated toward zero.
Properties
$nanoseconds read-only
The duration's total length in nanoseconds.
public
int|CooperInteger
$nanoseconds
Methods
__construct()
public
__construct(int|CooperInteger $nanoseconds) : mixed
Parameters
- $nanoseconds : int|CooperInteger
-
the duration's total length in nanoseconds; a
CooperIntegerthat fits is kept as anint
__toString()
The duration in its base unit -- `"500000000ns"` -- which is also valid CASC if fed back in.
public
__toString() : string
Return values
string —the nanosecond count with an ns suffix
equals()
public
equals(mixed $other) : bool
Parameters
- $other : mixed
-
the value to compare against
Return values
bool —true for a duration of the same length
toMicroseconds()
public
toMicroseconds() : int|CooperInteger
Return values
int|CooperInteger —the duration in whole microseconds, truncated toward zero
toMilliseconds()
public
toMilliseconds() : int|CooperInteger
Return values
int|CooperInteger —the duration in whole milliseconds, truncated toward zero
toSeconds()
public
toSeconds() : float
Return values
float —the duration in (fractional) seconds -- the nearest float, for a count beyond 64 bits
divided()
`$count` divided by `$divisor`, truncated toward zero.
private
static divided(int|CooperInteger $count, int $divisor) : int|CooperInteger
Parameters
- $count : int|CooperInteger
- $divisor : int