php-cooper

CooperTime
in package
implements Stringable, JsonSerializable

FinalYes

A CASC local time of day (CASC.md ยง6.6) -- `07:32:00`, optionally with fractional seconds -- matching Elixir's `Time`: microsecond resolution, and the number of fractional digits written (`$precision`, at most 6) kept so `07:32:00.5` renders back as written rather than as `07:32:00.500000`.

Table of Contents

Interfaces

Stringable
JsonSerializable

Properties

$hour  : int
$microsecond  : int
$minute  : int
$precision  : int
$second  : int

Methods

__construct()  : mixed
__toString()  : string
equals()  : bool
jsonSerialize()  : string
Encodes as the same text `__toString()` returns.
parse()  : self
Parses `HH:MM:SS` with optional fractional seconds; digits past the sixth are truncated, as Elixir's own `Time.from_iso8601/1` does.

Properties

$microsecond read-only

public int $microsecond = 0

Methods

__construct()

public __construct(int $hour, int $minute, int $second[, int $microsecond = 0 ][, int $precision = 0 ]) : mixed
Parameters
$hour : int

0..23

$minute : int

0..59

$second : int

0..59

$microsecond : int = 0

0..999999

$precision : int = 0

how many fractional digits to render, 0..6

Tags
throws
InvalidArgumentException

when a field is out of range

__toString()

public __toString() : string
Return values
string —

HH:MM:SS, plus $precision fractional digits when non-zero

equals()

public equals(mixed $other) : bool
Parameters
$other : mixed

the value to compare against

Return values
bool —

true for the same time of day and precision

jsonSerialize()

Encodes as the same text `__toString()` returns.

public jsonSerialize() : string
Return values
string —

the string form

parse()

Parses `HH:MM:SS` with optional fractional seconds; digits past the sixth are truncated, as Elixir's own `Time.from_iso8601/1` does.

public static parse(string $text) : self
Parameters
$text : string

e.g. "07:32:00.5"

Tags
throws
InvalidArgumentException

when $text is not a valid time

Return values
self —

the parsed time

On this page

Search results