public function DrupalDateTime::__construct

Constructs a date object.

Parameters

mixed $time: A DateTime object, a date/input_time_adjusted string, a unix timestamp, or an array of date parts, like ('year' => 2014, 'month => 4). Defaults to 'now'.

mixed $timezone: PHP DateTimeZone object, string or NULL allowed. Defaults to NULL.

string $format: PHP date() type format for parsing the input. This is recommended to use things like negative years, which php's parser fails on, or any other specialized input with a known format. If provided the date will be created using the createFromFormat() method. Defaults to NULL. @see http://us3.php.net/manual/en/datetime.createfromformat.php

array $settings:

  • validate_format: (optional) Boolean choice to validate the created date using the input format. The format used in createFromFormat() allows slightly different values than format(). Using an input format that works in both functions makes it possible to a validation step to confirm that the date created from a format string exactly matches the input. This option indicates the format can be used for validation. Defaults to TRUE.
  • langcode: (optional) String two letter language code to construct the locale string by the intlDateFormatter class. Used to control the result of the format() method if that class is available. Defaults to NULL.
  • country: (optional) String two letter country code to construct the locale string by the intlDateFormatter class. Used to control the result of the format() method if that class is available. Defaults to NULL.
  • calendar: (optional) String calendar name to use for the date. Defaults to DateTimePlus::CALENDAR.
  • debug: (optional) Boolean choice to leave debug values in the date object for debugging purposes. Defaults to FALSE.

Overrides DateTimePlus::__construct

File

drupal/core/lib/Drupal/Core/Datetime/DrupalDateTime.php, line 60
Definition of Drupal\Core\Datetime\DrupalDateTime.

Class

DrupalDateTime
Extends DateTimePlus().

Namespace

Drupal\Core\Datetime

Code

public function __construct($time = 'now', $timezone = NULL, $format = NULL, $settings = array()) {

  // We can set the langcode and country using Drupal values.
  $settings['langcode'] = !empty($settings['langcode']) ? $settings['langcode'] : language(Language::TYPE_INTERFACE)->langcode;
  $settings['country'] = !empty($settings['country']) ? $settings['country'] : config('system.date')
    ->get('country.default');

  // Instantiate the parent class.
  parent::__construct($time, $timezone, $format, $settings);
}