MongoDateConversion

Can be used by any class which accesses MongoDB.

trait MongoDateConversion
Copyright
2015-2016 Appertly
License
Apache-2.0

Instance Methods

Protected
ReturnsSignature and Description
?DateTime
toDateTime(mixed $value, ?DateTimeZone $timeZone = null)

Tries to convert a UTCDateTime into a DateTime.

?DateTimeImmutable
toDateTimeImmutable(mixed $value)

Tries to convert a UTCDateTime into a DateTimeImmutable.

Method Details

toDateTime

protected function toDateTime(mixed $value, ?DateTimeZone $timeZone = null)

Tries to convert a UTCDateTime into a DateTime.

Parameters
NameTypeDescription
$valuemixed

The value to convert

$timeZone?DateTimeZone

Optional Time Zone to set

Returns
TypeDescription
?DateTime

The date if $value is a UTCDateTime, null otherwise

toDateTimeImmutable

protected function toDateTimeImmutable(mixed $value)

Tries to convert a UTCDateTime into a DateTimeImmutable.

Parameters
NameTypeDescription
$valuemixed

The value to convert

Returns
TypeDescription
?DateTimeImmutable

The date if $value is a UTCDateTime, null otherwise