class DateTime (View source)

Methods

DateTime|string|null
translate(string $field, array $arr = null, bool $asDateTime = false)

Takes a "field" and grabs all the corresponding disparate fields from $_POST and translates into a timestamp.

string
datetime(string $field, DateTime|string $value = null, bool $includeActivation = false, bool $calendarAutoStart = true, string $classes = null, int $timeResolution = 60)

Creates form fields and JavaScript calendar includes for a particular item (date/time string representations will be converted from the user system-zone to the time-zone).

date(string $field, DateTime|string $value = null, bool $calendarAutoStart = true)

Creates form fields and JavaScript calendar includes for a particular item but includes only calendar controls (no time, so no time-zone conversions will be applied).

int
selectNearestValue(array $values, int $wantedValue)

Choose an array value nearest to a specified value.

Details

DateTime|string|null translate(string $field, array $arr = null, bool $asDateTime = false)

Takes a "field" and grabs all the corresponding disparate fields from $_POST and translates into a timestamp.

If $field has both date and time, the resulting value will be converted from the user timezone to the system timezone. If $field has only date and not time, no timezone conversion will occur.

Parameters

string $field

The name of the field to translate

array $arr

The array containing the value. If null (default) we'll use $_POST

bool $asDateTime

Set to true to get a DateTime object, false (default) for a string representation

Return Value

DateTime|string|null

In case of success returns the timestamp (in the format 'Y-m-d H:i:s' or 'Y-m-d' if $asDateTime is false) or the DateTime instance (if $asDateTime is true); if the date/time was not received we'll return null (if $field value is empty)

string datetime(string $field, DateTime|string $value = null, bool $includeActivation = false, bool $calendarAutoStart = true, string $classes = null, int $timeResolution = 60)

Creates form fields and JavaScript calendar includes for a particular item (date/time string representations will be converted from the user system-zone to the time-zone).

Parameters

string $field

The field prefix (will be used as $field parameter in the translate method)

DateTime|string $value

The initial value

bool $includeActivation

Set to true to include a checkbox to enable/disable the date/time fields

bool $calendarAutoStart

Set to false to avoid initializing the Javascript calendar

string $classes

A list of space-separated classes to add to the ui-datepicker-div container

int $timeResolution

The time resolution in seconds (60 means we won't ask seconds)

Return Value

string

date(string $field, DateTime|string $value = null, bool $calendarAutoStart = true)

Creates form fields and JavaScript calendar includes for a particular item but includes only calendar controls (no time, so no time-zone conversions will be applied).

Parameters

string $field

The field name (will be used as $field parameter in the translate method)

DateTime|string $value

The initial value

bool $calendarAutoStart

Set to false to avoid initializing the Javascript calendar

protected int selectNearestValue(array $values, int $wantedValue)

Choose an array value nearest to a specified value.

Useful when we work with time resolutions.

Parameters

array $values
int $wantedValue

Return Value

int

Examples

If the current time is 10 and the time resolution is 15, we have an array of values of [0, 15, 30, 45]: the closest value is 15.