Flow PHP

DateTimeType implements Type

Read onlyYes
FinalYes
Tags
implements

Interfaces

Type

Constants

ISO_DATE_TIME  : string = '/^(\d{4})-(\d{2})-(\d{2})[T ](?:[01]\d|2[0-4])...

Methods

__construct()  : mixed
assert()  : T
Checks that the value is of the type of this object, throwing when it is not.
cast()  : T
Takes a value and when necessary casts it to the type of this object.
fromArray()  : self
isValid()  : bool
Checks if the value is of the type of this object, returning a boolean instead of throwing.
normalize()  : array{type: "datetime", zone: string}
toString()  : string
Returns a string representation of the type.
zone()  : DateTimeZone
zoneName()  : string

Constants

ISO_DATE_TIME

public string ISO_DATE_TIME = '/^(\d{4})-(\d{2})-(\d{2})[T ](?:[01]\d|2[0-4]):[0-5]\d(?::(?:[0-5]\d|60)(?:\.\d{1,9})?)?(Z|[+-](?:(?:[01]\d|2[0-4]):?[0-5]\d|\d{2}))?$/'

Methods

__construct()

public __construct([DateTimeZone|string $zone = 'UTC' ]) : mixed
Parameters
$zone : DateTimeZone|string = 'UTC'

assert()

Checks that the value is of the type of this object, throwing when it is not.

public assert(mixed $value) : T

Unlike cast(), this method never performs any conversion — the value must already match the type. Unlike isValid(), this method returns the value (narrowed to T) instead of a boolean, and always narrows the static type.

Parameters
$value : mixed
Return values
T

cast()

Takes a value and when necessary casts it to the type of this object.

public cast(mixed $value) : T

When value is already of the type of this object, it is returned as is. When cast method is used, it will additionally narrow the type of the returned value for static analysis tools.

Parameters
$value : mixed
Return values
T

fromArray()

public static fromArray(array<string, mixed> $data) : self
Parameters
$data : array<string, mixed>
Return values
self

isValid()

Checks if the value is of the type of this object, returning a boolean instead of throwing.

public isValid(mixed $value) : bool

When this method returns true, static analysis tools narrow the value's type to T at the call site (via @assert-if-true). Use this when you want to branch on the result; use assert() when you want the call to fail loudly on a mismatch.

Parameters
$value : mixed
Return values
bool

normalize()

public normalize() : array{type: "datetime", zone: string}
Return values
array{type: "datetime", zone: string}

toString()

Returns a string representation of the type.

public toString() : string
  • string - for type_string()
  • int - for type_int()
  • ?float - for type_optional(type_float())
Return values
string

zone()

public zone() : DateTimeZone
Return values
DateTimeZone

zoneName()

public zoneName() : string
Return values
string
On this page

Search results