public class DateTimeObj

class.datetimeobj.php #14

The DateTimeObj provides static functions regarding dates in Symphony. Symphony will set the default timezone of the system using the value from the Configuration values. Alternatively a new settings can be set using the setSettings function. Symphony parses all input dates against the Configuration date formats by default for better support with non English dates.

Methods

static string convertDateToMoment(string $format)

Returns the Moment representation of a given PHP format token.

Parameters
  • $format stringA valid PHP date token

static string convertMomentToDate(string $format)

Returns the PHP representation of a given Moment format token.

Parameters
  • $format stringA valid Moment date token

static string convertMomentToTime(string $format)

Returns the PHP time representation of a given Moment format token.

Parameters
  • $format stringA valid Moment time token

static string convertTimeToMoment(string $format)

Returns the Moment time representation of a given PHP format token.

Parameters
  • $format stringA valid PHP time token

static string|boolean format(string $string, string $format, boolean $localize, string $timezone)

Formats the given date and time $string based on the given $format. Optionally the result will be localized and respect a timezone differing from the system default. The default output is ISO 8601.

Parameters
  • $string string(optional) A string containing date and time, defaults to the current date and time

  • $format string(optional) A valid PHP date format, defaults to ISO 8601

  • $localize boolean(optional) Localizes the output, if true, defaults to true

  • $timezone string(optional) The timezone associated with the timestamp

Returns

The formatted date, or if the date could not be parsed, false.

static string|boolean get(string $format, null|string $timestamp, string $timezone)

Given a $format, and a $timestamp, return the date in the format provided. This function is a basic wrapper for PHP's DateTime object. If the $timestamp is omitted, the current timestamp will be used. Optionally, you pass a timezone identifier with this function to localise the output

If you like to display a date in the backend, please make use of DateTimeObj::format() which allows date and time localization

Parameters
  • $format stringA valid PHP date format

  • $timestamp null|string(optional) A unix timestamp to format. 'now' or omitting this parameter will result in the current time being used

  • $timezone string(optional) The timezone associated with the timestamp

Returns

The formatted date, of if the date could not be parsed, false.

See Also
static array getDateFormatMappings()

Returns an array of PHP date formats Symphony supports mapped to their Moment equivalent.

static array getDateFormats()

Returns an array of the date formats Symphony supports. These formats are a combination of valid PHP format tokens.

See Also
static array getDateFormatsSelectOptions(string $selected)

Returns an array of the date formats Symphony supports by applying the format to the current datetime. The array returned is for use with Widget::Select()

Parameters
  • $selected stringA preselected date format, defaults to null

Returns

An associative array, for use with Widget::Select

See Also
static string getGMT(string $format, null|string $timestamp)

A wrapper for get, this function will force the GMT timezone.

Parameters
  • $format stringA valid PHP date format

  • $timestamp null|string(optional) A unix timestamp to format. Omitting this parameter will result in the current time being used

Returns

The formatted date in GMT

static array getMomentDateFormats()

Returns an array of the date formats Symphony supports. These formats are a combination of valid Moment format tokens.

See Also
static array getMomentTimeFormats()

Returns an array of the time formats Symphony supports. These formats are a combination of valid Moment format tokens.

See Also
static array|string|null getSetting(string $name)

Accessor function for the settings of the DateTimeObj. Currently the available settings are time_format, date_format, datetime_format and datetime_separator. If $name is not provided, the entire $settings array is returned.

Returns

If $name is omitted this function returns array. If $name is not set, this fucntion returns null If $name is set, this function returns string

static array getTimeFormats()

Returns an array of the time formats Symphony supports. These formats are a combination of valid PHP format tokens.

See Also
static array getTimeFormatsSelectOptions(string $selected)

Returns an array of the time formats Symphony supports by applying the format to the current datetime. The array returned is for use with Widget::Select()

Parameters
  • $selected stringA preselected time format, defaults to null

Returns

An associative array, for use with Widget::Select

See Also
static array getTimezones(string $zone)

This functions acts as a standard way to get the timezones regardless of PHP version. It accepts a single parameter, zone, which returns the timezones associated with that 'zone'

Parameters
  • $zone stringThe zone for the timezones the field wants. This maps to the DateTimeZone constants

See Also
static array getTimezonesSelectOptions(string $selected)

Loads all available timezones using getTimezones() and builds an array where timezones are grouped by their region (Europe/America etc.) The options array that is returned is designed to be used with Widget::Select

Parameters
  • $selected stringA preselected timezone, defaults to null

Returns

An associative array, for use with Widget::Select

See Also
static array getZones()

This functions acts as a standard way to get the zones available on the system.

See Also
static DateTime|boolean parse(string $string)

Parses the given string and returns a DateTime object.

Parameters
  • $string string(optional) A string containing date and time, defaults to the current date and time

Returns

The DateTime object, or if the date could not be parsed, false.

static void setDefaultTimezone(string $timezone)

Uses PHP's datedefaulttimezone_set function to set the system timezone. If the timezone provided is invalid, a E_USER_WARNING will be raised.

Parameters
  • $timezone stringA valid timezone identifier, such as UTC or Europe/Lisbon

See Also
static void setSettings(array $settings)

This function takes an array of settings for DateTimeObj to use when parsing input dates. The following settings are supported, time_format, date_format, datetime_separator and timezone. This equates to Symphony's default region group set in the Configuration class. If any of these values are not provided the class will fallback to existing self::$settings values

Parameters
  • $settings arrayAn associative array of formats for this class to use to format dates

static boolean validate(string $string)

Validate a given date and time string

Parameters
  • $string stringA date and time string or timestamp to validate

Returns

Returns true for valid dates, otherwise false

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details