public function TimelineDate::__construct in Views TimelineJS integration 7.3
File
- src/
TimelineDate.php, line 13
Class
- TimelineDate
- Converts date strings to TimelineJS3-compatible date arrays.
Code
public function __construct($date_string, DateTimeZone $timezone = NULL) {
$this->date_string = $date_string;
// Disallow empty date strings. They will cause DateTime::__construct() to
// return a date object with the current time.
if (empty($date_string)) {
throw new Exception('Empty date strings are not allowed.');
}
// Check for date strings that only include a year value.
if (is_numeric($date_string)) {
// Append '-01-01' to year-only values. By specifying a month and day
// before the value is parsed, year-only values can be used as input.
$date_string .= '-01-01';
}
// Explicitly set timezone for versions of PHP prior to 5.3.6.
// @see https://bugs.php.net/bug.php?id=52063
if (phpversion() < '5.3.6' && $timezone === NULL) {
$timezone = new DateTimeZone(date_default_timezone_get());
}
parent::__construct($date_string, $timezone);
}