/**
  * Force an incomplete date to be valid, for instance to add
  * a valid year, month, and day if only the time has been defined.
  *
  * @param $date
  *   An array of date parts or a datetime string with values to be forced into date.
  * @param $format
  *   The format of the date.
  * @param $default 
  *   'current' - default to current day values.
  *   'first' - default to the first possible valid value.
  */
 public function setFuzzyDate($date, $format = NULL, $default = 'first')
 {
     $timezone = $this->getTimeZone() ? $this->getTimeZone()->getName() : NULL;
     $comp = new DateObject($date, $timezone, $format);
     $arr = $comp->toArray(TRUE);
     foreach ($arr as $key => $value) {
         // Set to intval here and then test that it is still an integer.
         // Needed because sometimes valid integers come through as strings.
         $arr[$key] = $this->forceValid($key, intval($value), $default, $arr['month'], $arr['year']);
     }
     $this->setDate($arr['year'], $arr['month'], $arr['day']);
     $this->setTime($arr['hour'], $arr['minute'], $arr['second']);
 }
 *
 * @see template_preprocess()
 * @see template_preprocess_node()
 * @see template_process()
 */
?>

<?php 
$start = NULL;
if (!empty($node->node_announce_start_date['und'][0]['value'])) {
    $start = new DateObject($node->node_announce_start_date['und'][0]['value'], new DateTimeZone($node->node_announce_start_date['und'][0]['timezone_db']), 'Y-m-d\\TH:i:s');
    $start->setTimeZone(new DateTimeZone($node->node_announce_start_date['und'][0]['timezone']));
}
$end = NULL;
if (!empty($node->node_announce_end_date['und'][0]['value'])) {
    $end = new DateObject($node->node_announce_end_date['und'][0]['value'], new DateTimeZone($node->node_announce_end_date['und'][0]['timezone_db']), 'Y-m-d\\TH:i:s');
    $end->setTimeZone(new DateTimeZone($node->node_announce_end_date['und'][0]['timezone']));
}
?>
<tr>
	<td valign="top">
		<table cellspacing="0" cellpadding="0" border="0" align="center" width="100%">
			<tbody>
				<tr>
					<td height="49" width="100%" valign="middle" bgcolor="#c8cfd8" background="<?php 
global $base_url;
echo $base_url . "/";
echo drupal_get_path('module', 'amivannounce');
?>
/images/article-title-bg.png" style="vertical-align:middle; border-left-width: 1px; border-left-color: #BAC2CC; border-left-style: solid; border-right-width: 1px; border-right-color: #BAC2CC; border-right-style: solid; border-bottom-width: 1px; border-bottom-color: #98a3b4; border-bottom-style: solid; border-top-width: 1px; border-top-color: #BAC2CC; border-top-style: solid;">
						<h3 class="textshadow" style="margin:0; margin-left: 17px; padding:0; font-size: 18px; font-weight: normal; color:#324258;">
																										<p style="font-size: 13px; line-height: 20px; font-weight: normal; color: #56667d; margin: 0; margin-bottom: 0px;margin-left:13px;">
																											<b><i>Information</i></b> 
																										</p>
																									</td>
																								</tr>																								
																								<?php 
$agendas = array();
foreach ($nodes as $node) {
    $start = NULL;
    if (!empty($node->node_announce_start_date['und'][0]['value'])) {
        $start = new DateObject($node->node_announce_start_date['und'][0]['value'], new DateTimeZone($node->node_announce_start_date['und'][0]['timezone_db']), 'Y-m-d\\TH:i:s');
        $start->setTimeZone(new DateTimeZone($node->node_announce_start_date['und'][0]['timezone']));
    }
    $end = NULL;
    if (!empty($node->node_announce_end_date['und'][0]['value'])) {
        $end = new DateObject($node->node_announce_end_date['und'][0]['value'], new DateTimeZone($node->node_announce_end_date['und'][0]['timezone_db']), 'Y-m-d\\TH:i:s');
        $end->setTimeZone(new DateTimeZone($node->node_announce_end_date['und'][0]['timezone']));
    }
    if (!empty($node->node_announce_start_date['und'][0]['value'])) {
        ?>
																								<tr>
																									<td  width="45%">
																										<p style="font-size: 12px;  font-weight: normal; color: #56667d; margin: 0;margin-left:17px;">
																											<?php 
        echo $start->format('d.m.y H:i') . " :: ";
        echo !empty($node->node_announce_shorttitle['de'][0]['safe_value']) ? $node->node_announce_shorttitle['de'][0]['safe_value'] : $node->node_announce_shorttitle['en'][0]['safe_value'];
        ?>
																										</p>
																									</td>
																									<td>
																										<p style="font-size: 12px; font-weight: normal; color: #56667d; margin: 0;margin-left:17px;">
 protected function calcola_costo_listino_base($sito_parcheggio, $nr_giorni, $nr_giorni_aggiuntivi)
 {
     $result = 0;
     $this->valore_sct_p_online = 0;
     $this->sct_p_online = 0;
     $oggi = new DateObject();
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'listino_base')->propertyCondition('status', 1)->fieldCondition('field_lb_sp_codice', 'nid', $sito_parcheggio)->fieldCondition('field_lb_classe_servizio', 'value', ucfirst($this->ar_data['tipo_parcheggio']))->fieldCondition('field_lb_data_validita_finale', 'value', $oggi->format("Y-m-d"), '>=')->addMetaData('account', user_load(1));
     $qryres = $query->execute();
     if (isset($qryres['node'])) {
         $items_nids = array_keys($qryres['node']);
         $k = $items_nids[0];
         $items = entity_load('node', $items_nids);
         $costo = $this->getCostiSingoloGiorno($items, $nr_giorni, $nr_giorni_aggiuntivi);
         // sconto p online
         $this->sct_p_online = $items[$k]->field_sct_prenotazione_online['und']['0']['value'];
         if ($this->ar_data['p_online'] == 1 && $this->sct_p_online != 0) {
             $this->valore_sct_p_online = $costo * ($this->sct_p_online / 100);
             $costo = $costo - $this->valore_sct_p_online;
         }
         $result = $costo;
     }
     return $result;
 }
function unity_lab_it_preprocess_paragraphs_item_system_status_section(&$vars, $hook)
{
    if (arg(0) == 'node' && is_numeric(arg(1))) {
        // creating the node variable
        $node = node_load(arg(1), NULL, TRUE);
    }
    $vars['content']['show_all_link'] = false;
    $vars['content']['show_archive_link'] = false;
    if ($node->nid == 19906) {
        $vars['content']['system_status_html'] = doit_system_status_front_view_unity3();
        $vars['content']['show_all_link'] = true;
    } else {
        if ($node->nid == 20616) {
            $vars['content']['system_status_html'] = doit_system_status_all_view_unity3();
            $vars['content']['show_archive_link'] = true;
        }
    }
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'system_status')->propertyCondition('status', 1)->fieldCondition('field_status_start_date', 'value', date("Y-m-d g:i:s"), '>')->fieldOrderBy('field_status_start_date', 'value', 'ASC')->range(0, 6);
    $result = $query->execute();
    if (isset($result['node'])) {
        $nids = array_keys($result['node']);
        $nodes = entity_load('node', $nids);
    }
    $nodeItems = array();
    $items = array();
    foreach ($nodes as $node) {
        $item['title'] = 'Scheduled Maintenance';
        $item['url'] = url('node/' . $node->nid);
        $start = field_get_items('node', $node, 'field_status_start_date');
        $start = empty($start[0]['value']) ? '' : $start[0]['value'];
        if ($start) {
            $start = new DateObject($start, 'UTC');
            $start->setTimeZone(new DateTimeZone('America/New_York'));
            $item['start-date'] = $start->format('F jS, Y g:i a');
            $item['start-date-only'] = $start->format('F jS, Y');
            $item['start-time-only'] = $start->format('g:i a');
        }
        $end = field_get_items('node', $node, 'field_status_end_date');
        $end = empty($end[0]['value']) ? '' : $end[0]['value'];
        if ($end) {
            $end = new DateObject($end, 'UTC');
            $end->setTimeZone(new DateTimeZone('America/New_York'));
            $item['end-date'] = $end->format('F jS, Y g:i a');
            $item['end-date-only'] = $end->format('F jS, Y');
            $item['end-time-only'] = $end->format('g:i a');
        }
        $systems = field_get_items('node', $node, 'field_system');
        $system = empty($systems[0]['target_id']) ? '' : $systems[0]['target_id'];
        if ($system) {
            $system = node_load($system);
            $item['title'] = $system->title;
        }
        if (count($systems) > 1) {
            $item['title'] .= ' and Additional Services';
        }
        $vars['content']['items'][] = $item;
    }
}
     $date = $slider_dates[$index];
     // 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'));
 public function render($row)
 {
     if (!$this->isUdate) {
         return parent::render($row);
     }
     $rows = array();
     $id = $row->{$this->field_alias};
     if (!is_numeric($id)) {
         return $rows;
     }
     // Load the specified node:
     // We have to clone this or nodes on other views on this page,
     // like an Upcoming block on the same page as a calendar view,
     // will end up acquiring the values we set here.
     $entity = clone $this->entities[$id];
     if (empty($entity)) {
         return $rows;
     }
     $info = entity_get_info($this->entity_type);
     $this->id_field = $info['entity keys']['id'];
     $this->id = $entity->{$this->id_field};
     $this->type = !empty($info['entity keys']['bundle']) ? $info['entity keys']['bundle'] : $this->entity_type;
     $this->title = entity_label($this->entity_type, $entity);
     $uri = entity_uri($this->entity_type, $entity);
     $uri['options']['absolute'] = TRUE;
     $this->url = url($uri['path'], $uri['options']);
     $field_name = $this->udateField;
     $entity->date_id = array();
     $granularity = 'second';
     $this->date_argument->view->date_info->display_timezone_name = date_default_timezone_get();
     // Set the date_id for the node, used to identify which field
     // value to display for fields that have multiple values. The
     // theme expects it to be an array.
     $date_id = 'date_id_' . $field_name;
     $date_delta = 'date_delta_' . $field_name;
     $delta = 0;
     if (isset($row->{$date_id})) {
         $entity->date_id = array('calendar.' . $row->{$date_id} . '.' . $field_name . '.' . $delta);
     } else {
         $entity->date_id = array('calendar.' . $id . '.' . $field_name . '.' . $delta);
     }
     if (!($items = field_get_items($this->entity_type, $entity, $field_name)) || !isset($items[$delta])) {
         return;
     }
     $item = $items[$delta];
     $fieldinfo = field_info_field($field_name);
     switch ($fieldinfo['type']) {
         case 'udate':
             $item_start_date = $item['date'];
             break;
         case 'udate_range':
             $item_start_date = $item['date_start'];
             $item_end_date = $item['date_end'];
             break;
         default:
             return;
     }
     if (empty($item_start_date)) {
         return;
     }
     if (empty($item_end_date)) {
         $item_end_date = $item_start_date;
     }
     if (class_exists('DateObject')) {
         $item_start_date = new DateObject($item_start_date->format(DateTime::ISO8601));
         $item_end_date = new DateObject($item_end_date->format(DateTime::ISO8601));
     }
     $event = new stdClass();
     $event->id = $this->id;
     $event->title = $this->title;
     $event->type = $this->type;
     $event->date_start = $item_start_date;
     $event->date_end = $item_end_date;
     $event->db_tz = date_default_timezone_get();
     $event->to_zone = date_default_timezone_get();
     $event->granularity = $granularity;
     $event->increment = 1;
     $event->field = $item;
     $event->url = $this->url;
     $event->row = $row;
     $event->entity = $entity;
     $event->stripe = array();
     $event->stripe_label = array();
     // All calendar row plugins should provide a date_id that the
     // theme can use.
     $event->date_id = $entity->date_id[0];
     // We are working with an array of partially rendered items
     // as we process the calendar, so we can group and organize them.
     // At the end of our processing we'll need to swap in the fully formatted
     // display of the row. We save it here and switch it in
     // template_preprocess_calendar_item().
     $event->rendered = theme($this->theme_functions(), array('view' => $this->view, 'options' => $this->options, 'row' => $row, 'field_alias' => isset($this->field_alias) ? $this->field_alias : ''));
     $entities = $this->explode_values($event);
     foreach ($entities as $entity) {
         switch ($this->options['colors']['legend']) {
             case 'type':
                 $this->calendar_node_type_stripe($entity);
                 break;
             case 'taxonomy':
                 $this->calendar_taxonomy_stripe($entity);
                 break;
             case 'group':
                 $this->calendar_group_stripe($entity);
                 break;
         }
         $rows[] = $entity;
     }
     return $rows;
 }