class Timezone (View source)

Helper class to work with database time zones.

Properties

protected Connection $connection

The database connection.

protected Date $dateHelper

The date date.

private array|null $databaseTimestamps

Cache the result of getDatabaseTimestamps.

private string|null $databaseTimezoneName

Cache the result of getDatabaseTimezoneName().

Methods

__construct(Connection $connection, Date $dateHelper)

Inizialize the instance.

array
getCompatibleTimezones()

Get a list of time zones that are compatible with the database.

null|array
getDeltaTimezone(DateTimeZone|string $phpTimezone)

Check if a PHP time zone is compatible with the database timezone.

string
describeDeltaTimezone(array $deltaTimezone)

Get a textual representation of the result of getDeltaTimezone().

array
getDatabaseTimestamps()

Get a list of date/times checked against the database.

string|null
getDatabaseTimezoneName()

Get the database time zone name (example: 'SYSTEM').

Details

__construct(Connection $connection, Date $dateHelper)

Inizialize the instance.

Parameters

Connection $connection

the database connection to check the time zones against

Date $dateHelper

the date helper

array getCompatibleTimezones()

Get a list of time zones that are compatible with the database.

Return Value

array

array keys are the time zone IDs (eg: 'Pacific/Pago_Pago'), array values are the localized time zone names

null|array getDeltaTimezone(DateTimeZone|string $phpTimezone)

Check if a PHP time zone is compatible with the database timezone.

Parameters

DateTimeZone|string $phpTimezone

Return Value

null|array

If the time zone matches, we'll return null, otherwise an array with the keys 'dstProblems' (boolean) and 'maxDeltaMinutes' (int)

Exceptions

Exception

throws an Exception if $phpTimezone is not recognised as a valid timezone

string describeDeltaTimezone(array $deltaTimezone)

Get a textual representation of the result of getDeltaTimezone().

Parameters

array $deltaTimezone

The result of getDeltaTimezone (when it's not null)

Return Value

string

protected array getDatabaseTimestamps()

Get a list of date/times checked against the database.

Return Value

array

{

@var int[] $timestamps the UNIX timestamps of the date/times checked
@var string[] $databaseDatetimes The corresponding date/time representations of the timestamps as formatted by the database.

}

string|null getDatabaseTimezoneName()

Get the database time zone name (example: 'SYSTEM').

Return Value

string|null