From a2d8d73b09260bf82df97a09f59098beaa4cae20 Mon Sep 17 00:00:00 2001
From: Lazarus-Long <Lazarus-Long@698858.no-reply.drupal.org>
Date: Thu, 31 May 2012 23:46:24 -0700
Subject: [PATCH] Fixed issues with compressed times

---
 office_hours.elements.inc |    4 +---
 office_hours.module       |    5 +++++
 office_hours.theme.inc    |   13 +++++++++----
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/office_hours.elements.inc b/office_hours.elements.inc
index 4b8e2a3..e1ea98a 100644
--- a/office_hours.elements.inc
+++ b/office_hours.elements.inc
@@ -68,9 +68,7 @@ function _office_hours_field_process($element, &$form_state, $form) {
  * Process the hours selector element.
  */
 function _office_hours_select_process($element, &$form_state, $form) {
-  if (is_numeric($element['#default_hours'])) {
-    list($defhr, $defmin, $ampm) = _office_hours_return_defaults($element['#default_hours'], $element['#hoursformat']); 
-  }
+  list($defhr, $defmin, $ampm) = _office_hours_return_defaults($element['#default_hours'], $element['#hoursformat']); 
 
   $hours = ($element['#hoursformat'] == 1) ? date_hours('g') : date_hours('H');
   if (!empty($element['#valhrs']) && !empty($element['#limitend']) ) {
diff --git a/office_hours.module b/office_hours.module
index fa1b0af..d046feb 100644
--- a/office_hours.module
+++ b/office_hours.module
@@ -466,11 +466,16 @@ function _office_hours_convert_to_ampm($hour) {
 }
 
 function _office_hours_return_defaults($default, $format = 0) {
+  if (!is_numeric($default)) {
+    return array('','','am');
+  }
+  
   $ampm = 'am';
   $defhr = '';
   $defmin = '';
   $hour = _office_hours_mil_to_tf($default);
   list($defhr, $defmin) = explode(":", $hour);
+
   if ($format) {
     if ($defhr >= 12) {
       $defhr -= ($defhr != 12) ? 12 : 0;
diff --git a/office_hours.theme.inc b/office_hours.theme.inc
index 931b962..2e95dd1 100644
--- a/office_hours.theme.inc
+++ b/office_hours.theme.inc
@@ -49,11 +49,14 @@ function office_hours_field_formatter_view($entity_type, $entity, $field, $insta
     
     $start  = check_plain($el['starthours']);
     $end    = check_plain($el['endhours']);
+    if ($start > $end && $end < 100) {
+      $end += 2400;
+    }
     
     $lines[$day]['times'][$alt]['start']  = $start;
     $lines[$day]['times'][$alt]['end']    = $end;
   }
-  
+
   // Check if we're compressing times
   if ($settings['compress']) {
     foreach ($lines as $day => &$info) {
@@ -63,13 +66,15 @@ function office_hours_field_formatter_view($entity_type, $entity, $field, $insta
         unset($info['times'][1]);
       }
     }
-  }
+  }  
+
   
   // Resort array to for the correct starting day
   $i = 0;
   $firstDay = variable_get('date_first_day', 0);
-  while ($i++ < $firstDay) array_push($lines, array_shift($lines));
+  while ($i++ < $firstDay) array_push($lines, array_shift($lines));  
   
+
   // Check if we're grouping days
   if ($settings['grouped']) {
     $times = $lines[0]['times'];
@@ -123,7 +128,7 @@ function theme_office_hours_formatter_default($vars) {
     }
     
     // Format the label
-    $label = $info['endday'] ? t($weekdays[$info['startday']]) . $settings['separator_grouped_days'] . t($weekdays[$info['endday']]) : t($weekdays[$info['startday']]);
+    $label = $info['endday'] !== null ? $weekdays[$info['startday']] . $settings['separator_grouped_days'] . $weekdays[$info['endday']] : $weekdays[$info['startday']];
     $label .= $settings['separator_day_hours'];
     
     // Format the time
-- 
1.7.10.msysgit.1

