public function DateTimePlus::__construct in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::__construct()
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.
1 call to DateTimePlus::__construct()
- DrupalDateTime::__construct in core/
lib/ Drupal/ Core/ Datetime/ DrupalDateTime.php - Constructs a date object.
1 method overrides DateTimePlus::__construct()
- DrupalDateTime::__construct in core/
lib/ Drupal/ Core/ Datetime/ DrupalDateTime.php - Constructs a date object.
File
- core/
lib/ Drupal/ Component/ Datetime/ DateTimePlus.php, line 246 - Contains \Drupal\Component\Datetime\DateTimePlus.
Class
- DateTimePlus
- Wraps DateTime().
Namespace
Drupal\Component\DatetimeCode
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);
}