/** * Overridden constructor. * * @param $time * time string, flexible format including timestamp. * @param $tz * PHP DateTimeZone object, string or NULL allowed, defaults to site timezone. * @param $format * PHP date() type format for parsing. Doesn't support timezones; if you have a timezone, send NULL * and the default constructor method will hopefully parse it. * $format is recommended in order to use negative or large years, which php's parser fails on. */ public function __construct($time = 'now', $tz = NULL, $format = NULL) { $this->timeOnly = FALSE; $this->dateOnly = FALSE; // Allow string timezones if (!empty($tz) && !is_object($tz)) { $tz = new DateTimeZone($tz); } elseif (empty($tz)) { $tz = date_default_timezone_object(); } // Special handling for Unix timestamps expressed in the local timezone. // Create a date object in UTC and convert it to the local timezone. // Don't try to turn things like '2010' with a format of 'Y' into a timestamp. if (is_numeric($time) && (empty($format) || $format == 'U')) { // Assume timestamp. $time = "@" . $time; $date = new DateObject($time, 'UTC'); if ($tz->getName() != 'UTC') { $date->setTimezone($tz); } $time = $date->format(DATE_FORMAT_DATETIME); $format = DATE_FORMAT_DATETIME; } if (is_array($time)) { // Assume we were passed an indexed array. if (empty($time['year']) && empty($time['month']) && empty($time['day'])) { $this->timeOnly = TRUE; } if (empty($time['hour']) && empty($time['minute']) && empty($time['second'])) { $this->dateOnly = TRUE; } $this->errors = $this->arrayErrors($time); // Make this into an ISO date, // forcing a full ISO date even if some values are missing. $time = $this->toISO($time, TRUE); // We checked for errors already, skip the step of parsing the input values. $format = NULL; } // The parse function will also set errors on the date parts. if (!empty($format)) { $arg = self::$allgranularity; $element = array_pop($arg); while (!$this->parse($time, $tz, $format) && $element != 'year') { $element = array_pop($arg); $format = date_limit_format($format, $arg); } if ($element == 'year') { return FALSE; } } elseif (is_string($time)) { // PHP < 5.3 doesn't like the GMT- notation for parsing timezones. $time = str_replace("GMT-", "-", $time); $time = str_replace("GMT+", "+", $time); // We are going to let the parent dateObject do a best effort attempt to turn this // string into a valid date. It might fail and we want to control the error messages. try { @parent::__construct($time, $tz); } catch (Exception $e) { $this->errors['date'] = $e; return; } $this->setGranularityFromTime($time, $tz); } // This tz was given as just an offset, which causes problems, // or the timezone was invalid. if (!$this->getTimezone() || !preg_match('/[a-zA-Z]/', $this->getTimezone()->getName())) { $this->setTimezone(new DateTimeZone("UTC")); } }
// Check if it's expired: if (isset($date['value2'])) { $expiration_date = strtotime($date['value2']); if (time() > $expiration_date) { unset($current_node->field_hero_image[$language_prefix][$index]); unset($current_node->field_title[$language_prefix][$index]); unset($current_node->field_slider_date[$language_prefix][$index]); unset($current_node->field_slider_teaser[$language_prefix][$index]); unset($current_node->field_link[$language_prefix][$index]); $rewrite_node = true; continue; } } // Convert from the database time zone to the user's time zone. $date_object = new DateObject($date['value'], new DateTimeZone($date['timezone_db'])); $date_object->setTimezone(new DateTimeZone($date['timezone'])); $slider_date_formatted = date_format_date($date_object, 'custom', $date_format); //date($date_format, strtotime($slider_dates[$index]['value']) ); } $slider_title_formatted = $slider_titles[$index]['value']; $slide_pos += 1; if ($slide_pos === 1) { $navClass = 'active'; $slideClass = 'first active'; } else { $navClass = ''; $slideClass = ''; } $slide = "<div class='slide {$slideClass}' number='{$slide_pos}'>"; $image = theme_image_formatter(array('item' => $slider_image, 'image-style' => 'original')); $slide .= "<div class='slide-image image-cover'>{$image}</div>";