CoolCMS API

DateTimeHelper
in package

Table of Contents

Methods

convertToDateTime()  : DateTime|null
Convert a string or \DateTime or null to a \DateTime object.
utcToAppTime()  : string|null
Stored UTC string (`Y-m-d H:i:s` without a zone, the DB is in UTC) to text in the application time zone (`php: date.timezone` in `config/common.neon`, Europe/Prague). For display and form prefill whose save takes the input as Prague time and converts it to UTC (e.g.

Methods

convertToDateTime()

Convert a string or \DateTime or null to a \DateTime object.

public static convertToDateTime(mixed $dateTime) : DateTime|null
Parameters
$dateTime : mixed

\DateTime, string, {date, timezone} array or null; any other type throws

Tags
throws
InvalidArgumentException

if the value is of invalid type

Return values
DateTime|null

utcToAppTime()

Stored UTC string (`Y-m-d H:i:s` without a zone, the DB is in UTC) to text in the application time zone (`php: date.timezone` in `config/common.neon`, Europe/Prague). For display and form prefill whose save takes the input as Prague time and converts it to UTC (e.g.

public static utcToAppTime(string $utc[, string $format = 'Y-m-d H:i:s' ]) : string|null

ProductSetManager::resolvePublishedTime()). The value is parsed explicitly as UTC; otherwise DateTimeImmutable would take it in the ambient zone and the time would not shift. Returns null for unparsable input (the caller decides on a replacement).

Parameters
$utc : string
$format : string = 'Y-m-d H:i:s'
Return values
string|null
On this page

Search results