Constructs a date object set to a requested date and timezone.
mixed $time: A DateTime object, a date/time 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 for 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:
public function __construct($time = 'now', $timezone = NULL, $format = NULL, $settings = array()) {
// Unpack settings.
$this->validateFormat = !empty($settings['validate_format']) ? $settings['validate_format'] : TRUE;
$this->langcode = !empty($settings['langcode']) ? $settings['langcode'] : NULL;
$this->country = !empty($settings['country']) ? $settings['country'] : NULL;
$this->calendar = !empty($settings['calendar']) ? $settings['calendar'] : static::CALENDAR;
// Store the original input so it is available for validation.
$this->inputTimeRaw = $time;
$this->inputTimeZoneRaw = $timezone;
$this->inputFormatRaw = $format;
// Massage the input values as necessary.
$this
->prepareTime($time);
$this
->prepareTimezone($timezone);
$this
->prepareFormat($format);
// Create a date as a clone of an input DateTime object.
if ($this
->inputIsObject()) {
$this
->constructFromObject();
}
elseif ($this
->inputIsArray()) {
$this
->constructFromArray();
}
elseif ($this
->inputIsTimestamp()) {
$this
->constructFromTimestamp();
}
elseif ($this
->inputIsFormat()) {
$this
->constructFromFormat();
}
else {
$this
->constructFallback();
}
// Clean up the error messages.
$this
->checkErrors();
$this->errors = array_unique($this->errors);
// Now that we've validated the input, clean up the extra values.
if (empty($settings['debug'])) {
unset($this->inputTimeRaw, $this->inputTimeAdjusted, $this->inputTimeZoneRaw, $this->inputTimeZoneAdjusted, $this->inputFormatRaw, $this->inputFormatAdjusted, $this->validateFormat);
}
}