DateTimePlus::__construct

public DateTimePlus::__construct($time = 'now', $timezone = NULL, $settings = array())

Constructs a date object set to a requested date and timezone.

Parameters

string $time: (optional) A date/time string. Defaults to 'now'.

mixed $timezone: (optional) \DateTimeZone object, time zone string or NULL. NULL uses the default system time zone. Defaults to NULL.

array $settings: (optional) Keyed array of settings. Defaults to empty array.

  • langcode: (optional) String two letter language code used to control the result of the format(). Defaults to NULL.
  • debug: (optional) Boolean choice to leave debug values in the date object for debugging purposes. Defaults to FALSE.

File

core/lib/Drupal/Component/Datetime/DateTimePlus.php, line 260

Class

DateTimePlus
Wraps DateTime().

Namespace

Drupal\Component\Datetime

Code

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

  // Unpack settings.
  $this->langcode = !empty($settings['langcode']) ? $settings['langcode'] : NULL;

  // Massage the input values as necessary.
  $prepared_time = $this->prepareTime($time);
  $prepared_timezone = $this->prepareTimezone($timezone);

  try {
    if (!empty($prepared_time)) {
      $test = date_parse($prepared_time);
      if (!empty($test['errors'])) {
        $this->errors[] = $test['errors'];
      }
    }

    if (empty($this->errors)) {
      $this->dateTimeObject = new \DateTime($prepared_time, $prepared_timezone);
    }
  }
  catch (\Exception $e) {
    $this->errors[] = $e->getMessage();
  }

  // Clean up the error messages.
  $this->checkErrors();
  $this->errors = array_unique($this->errors);
}
doc_Drupal
2016-10-29 09:01:04
Comments
Leave a Comment

Please login to continue.