Index: dayhour.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/dayhour.inc,v
retrieving revision 1.12
diff -u -p -r1.12 dayhour.inc
--- dayhour.inc	6 Mar 2007 23:49:18 -0000	1.12
+++ dayhour.inc	7 Mar 2007 00:36:37 -0000
@@ -4,6 +4,7 @@
 
 // there are 1440 minutes in a day (60minute * 24hours = 1day)
 define('MINUTES_IN_DAY', 1440);
+define('MINUTES_IN_HOUR', 60);
 
 /**
  * Turn an mixed into a valid hour.
@@ -124,7 +125,7 @@ function station_hour_name($hour = 0) {
  * @return integer minutes.
  */
 function station_minute_from_day_hour($day, $hour) {
-  return (($day * 24) + $hour) * 60;
+  return (($day * 24) + $hour) * MINUTES_IN_HOUR;
 }
 
 /**
@@ -137,7 +138,11 @@ function station_day_from_minute($minute
 }
 
 /**
- * Return an array of time information for the minutes since midnight sunday.
+ * Return an array of time information for the given minute count.
+ * @param $minutes integer of minutes since midnight sunday.
+ * @param $returnKey instead of returning an array, return the item with this 
+ * 		key.
+ * @return array of formatted time info keyed to the following: 
  * 'w' = Day of week (0-6)
  * 'G' = 24 hour
  * 'g' = 12 hour
@@ -148,16 +153,16 @@ function station_day_from_minute($minute
  * 'minutes' = minutes since midnight sunday
  * 'a' = am/pm
  */
-function station_time_from_minute($minutes) {
-  $min = $minutes % 60;
+function station_time_from_minute($minutes, $returnKey = NULL) {
+  $min = $minutes % MINUTES_IN_HOUR;
   $day = (int) (($minutes) / MINUTES_IN_DAY);
-  $hour24 = (int) (($minutes % MINUTES_IN_DAY) / 60);
+  $hour24 = (int) (($minutes % MINUTES_IN_DAY) / MINUTES_IN_HOUR);
   if (!($hour12 = $hour24 % 12)) {
     $hour12 = 12;
   }
   $i = str_pad($min, 2, '0', STR_PAD_LEFT);
   $h = str_pad($hour12, 2, '0', STR_PAD_LEFT);
-  return array(
+  $ret = array(
     'w' => $day,
     'G' => $hour24,
     'g' => $hour12,
@@ -168,6 +173,11 @@ function station_time_from_minute($minut
     'minutes' => $minutes,
     'a' => ($hour24 > 11) ? 'pm' : 'am',
   );
+  
+  if (!is_null($returnKey)) {
+    return $ret[$returnKey];
+  }
+  return $ret;
 }
 
 /**
Index: schedule/station_schedule.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/schedule/station_schedule.module,v
retrieving revision 1.31
diff -u -p -r1.31 station_schedule.module
--- schedule/station_schedule.module	12 Feb 2007 20:33:00 -0000	1.31
+++ schedule/station_schedule.module	7 Mar 2007 00:36:37 -0000
@@ -143,6 +143,13 @@ function station_schedule_admin_settings
     '#options' => array(15 => t('15 Minutes'), 30 => t('30 Minutes'), 60 => t('1 Hour')),
     '#description' => t("This is the minimum increment that programs can be scheduled in. <strong>Watch out:</strong> Changing this to a larger value on an existing schedule will probably cause wierdness."),
   );
+  
+  $form['station_schedule_grid_trim'] = array(
+    '#type' => 'checkbox',
+    '#title' => t("Hide unscheduled time on weekly schedule"),
+    '#default_value' => variable_get('station_schedule_grid_trim', 0),
+    '#description' => t('Check this to hide unscheduled hours at the beginning and end the day on the weekly schedule. '),
+  );
 
   $form['station_schedule_dj_title'] = array(
     '#type' => 'textfield',
@@ -590,9 +597,8 @@ function station_schedule_load_at($minut
 }
 
 function station_schedule_load_day($day) {
-  // there are 1440 minutes in a day (60minute * 24hours = 1day)
-  $start = $day * 1440;
-  $finish = $start + 1440;
+  $start = $day * MINUTES_IN_DAY;
+  $finish = $start + MINUTES_IN_DAY;
 
   $ret = array();
   $result = db_query('SELECT * FROM {station_schedule} s WHERE s.finish > %d AND s.start < %d ORDER BY s.start', $start, $finish);
@@ -618,15 +624,15 @@ function station_schedule_admin_list() {
   for ($i = 0; $i < 7; $i++) {
     $cell = '';
     // find the minute that the day starts and finishes
-    $day_start = $i * 1440;
-    $day_finish = $day_start + 1440;
-    $last_finish = $day_start;
+    $day_start = $i * MINUTES_IN_DAY;
+    $day_finish = $day_start + MINUTES_IN_DAY;
+    $printed_upto = $day_start;
     foreach (station_schedule_load_day($i) as $s) {
       // display blocks for unscheduled time periods
-      if ($last_finish != $s->start) {
-        $cell .= theme('station_schedule_admin_nonitem', $last_finish, $s->start);
+      if ($printed_upto != $s->start) {
+        $cell .= theme('station_schedule_admin_nonitem', $printed_upto, $s->start);
       }
-      $last_finish = $s->finish;
+      $printed_upto = $s->finish;
 
       // display the schedule item
       $height = ($s->finish - $s->start);
@@ -634,8 +640,8 @@ function station_schedule_admin_list() {
       $cell .= theme('station_schedule_admin_item', $s->sid, $s->start, $s->finish, $program);
     }
     // any remaining time during the day
-    if ($last_finish < $day_finish) {
-      $cell .= theme('station_schedule_admin_nonitem', $last_finish, $day_finish);
+    if ($printed_upto < $day_finish) {
+      $cell .= theme('station_schedule_admin_nonitem', $printed_upto, $day_finish);
     }
 
     $row[$i] = $cell;
@@ -725,7 +731,7 @@ function station_schedule_admin_form($op
   );
   $form['start_minutes'] = array(
     '#type' => 'select',
-    '#default_value' => $sch->start % 1440,
+    '#default_value' => $sch->start % MINUTES_IN_DAY,
     '#options' => $minute_options,
   );
   $form['finish_day'] = array(
@@ -737,7 +743,7 @@ function station_schedule_admin_form($op
   );
   $form['finish_minutes'] = array(
     '#type' => 'select',
-    '#default_value' => $sch->finish % 1440,
+    '#default_value' => $sch->finish % MINUTES_IN_DAY,
     '#options' => $minute_options,
   );
   $form['program_title'] = array(
@@ -774,8 +780,8 @@ function station_schedule_admin_form($op
 }
 
 function station_schedule_admin_form_validate($form_id, $form_values) {
-  $start = ($form_values['start_day'] * 1440) + $form_values['start_minutes'];
-  $finish = ($form_values['finish_day'] * 1440) + $form_values['finish_minutes'];
+  $start = ($form_values['start_day'] * MINUTES_IN_DAY) + $form_values['start_minutes'];
+  $finish = ($form_values['finish_day'] * MINUTES_IN_DAY) + $form_values['finish_minutes'];
 
   if ($start >= $finish) {
     form_set_error('finish', t("The program must start before it finishes."));
@@ -798,8 +804,8 @@ function station_schedule_admin_form_val
 }
 
 function station_schedule_admin_form_submit($form_id, $form_values) {
-  $start = ($form_values['start_day'] * 1440) + $form_values['start_minutes'];
-  $finish = ($form_values['finish_day'] * 1440) + $form_values['finish_minutes'];
+  $start = ($form_values['start_day'] * MINUTES_IN_DAY) + $form_values['start_minutes'];
+  $finish = ($form_values['finish_day'] * MINUTES_IN_DAY) + $form_values['finish_minutes'];
   $program = node_load(array('type' => 'program', 'title' => $form_values['program_title']));
 
   if ($form_values['sid']) {
@@ -868,81 +874,102 @@ function station_schedule_week_page() {
 
   $today = station_today();
 
+  // determing the first and last hours we'll display 
+  if( variable_get('station_schedule_grid_trim', 1) ) {
+    // get the earliest start time and latest finish time, in daily minutes
+    $o = db_fetch_object(db_query('SELECT MIN(MOD(start, 1440)) AS min, MAX(MOD(finish, 1440)) AS max FROM {station_schedule}'));
+    // and conver those to hours
+    $first_hour = station_time_from_minute($o->min, 'G');
+    $last_hour = station_time_from_minute($o->max, 'G');
+  }
+  else {
+    $first_hour = 0;
+    $last_hour = 24;    
+  }
+
   // build the headers
   $cols = array('data' => t('Time'));
   foreach (station_day_name() as $name) {
     $cols[] = array('data' => $name);
   }
-  // ... add a class to indicate what day it is.
-  $cols[$today]['class'] = 'station-sch-now-day';
 
+  // build the rows...
   $row = array();
-  // put in a column of hours
-  for ($i = 0; $i < 24; $i++) {
-    $cell .= theme('station_schedule_hour', $i);
-  }
-  $row[] = array('data' => $cell, 'id' => 'station-sch-hours');
-  // now a column for each day
-  for ($i = 0; $i < 7; $i++) {
-    $cell = '';
-    // find the minute that the day starts and finishes
-    $day_start = $i * 1440;
-    $day_finish = $day_start + 1440;
-    $last_finish = $day_start;
-    foreach (station_schedule_load_day($i) as $s) {
+
+  // ... first column is hours...
+  $column = '';
+  for ($hour = $first_hour; $hour < $last_hour; $hour++) {
+    $column .= theme('station_schedule_hour', $hour);
+  }
+  $row[] = array('data' => $column, 'id' => 'station-sch-hours');
+
+  // ... and now a column for each day
+  for ($day = 0; $day < 7; $day++) {
+    $column = '';
+
+    $day_start = (MINUTES_IN_DAY * $day) + ($first_hour * MINUTES_IN_HOUR);
+    $day_finish = (MINUTES_IN_DAY * $day) + ($last_hour * MINUTES_IN_HOUR);
+
+    $printed_upto = $day_start;
+    foreach (station_schedule_load_day($day) as $item) {
       // display blocks for unscheduled time before this program
-      if ($last_finish != $s->start) {
-        $cell .= theme('station_schedule_spacer', $last_finish, $s->start);
-      }
-      $last_finish = $s->finish;
-      // display the schedule item
-      $program = node_load($s->program_nid);
-      $cell .= theme('station_schedule_item', $s->start, $s->finish, $program);
-    }
-    // create an unscheduled block for any remaining time
-    if ($last_finish < $day_finish) {
-      $cell .= theme('station_schedule_spacer', $last_finish, $day_finish);
+      $column .= station_schedule_week_render_nonitem($printed_upto, $item->start);
+      $column .= station_schedule_week_render_item($item);
+      $printed_upto = $item->finish;
     }
-
-    $row[] = array('data' => $cell);
+    // an unscheduled block for any remaining time
+    $column .= station_schedule_week_render_nonitem($printed_upto, $day_finish);
+    
+    $row[] = array('data' => $column);
   }
+
+  // add a classes to indicate what day it is.
+  $cols[$today]['class'] = 'station-sch-now-day';
   $row[$today+1]['class'] = 'station-sch-now-day';
 
   // render the tables
   return theme('table', $cols, array($row), array('id' => 'station-sch'));
 }
 
+function station_schedule_week_render_item($item) {
+  // display the schedule item
+  $item->program = node_load($item->program_nid);
+  return theme('station_schedule_item', $item);
+}
+
+function station_schedule_week_render_nonitem($start, $finish) {
+  if ($start < $finish) {
+    return theme('station_schedule_spacer', $start, $finish);
+  }
+}
+
 function theme_station_schedule_hour($hour) {
-  $class = 'station-sch-box station-sch-hour';
   $height = 60;
-  $output = "<div class='{$class}' style='height:{$height}px;'>";
+  $output = "<div class='station-sch-box station-sch-hour' style='height:{$height}px;'>";
   $output .= station_hour_name($hour);
   $output .= "</div>\n";
   return $output;
 }
 
 function theme_station_schedule_spacer($start, $finish) {
-  $class = 'station-sch-box station-sch-unscheduled';
   $height = ($finish - $start);
-  $output = "<div class='{$class}' style='height:{$height}px;'>";
+  $output = "<div class='station-sch-box station-sch-unscheduled' style='height:{$height}px;'>";
   $output .= "<div class='station-sch-time'>". theme('station_hour_range', $start, $finish) ."</div>";
   $output .= "</div>\n";
   return $output;
 }
 
-function theme_station_schedule_item($start, $finish, $program) {
-  $class = 'station-sch-box station-sch-scheduled';
-  $height = ($finish - $start);
-  $output = "<div class='{$class}' style='height:{$height}px;'>\n";
-  $output .= "<div class='station-sch-time'>". theme('station_hour_range', $start, $finish) ."</div>";
-  $output .= check_plain($program->title);
-  if ($program->djs) {
-    $djs = _station_schedule_program_load_djs($program->nid);
-    $djs = check_plain(implode(', ', $djs));
-    $output .= "<div class='station-sch-djs'>{$djs}</div>";
+function theme_station_schedule_item($item) {
+  $height = ($item->finish - $item->start);
+  $output = "<div class='station-sch-box station-sch-scheduled' style='height:{$height}px;'>\n";
+  $output .= "<div class='station-sch-time'>". theme('station_hour_range', $item->start, $item->finish) ."</div>";
+  $output .= check_plain($item->program->title);
+  if ($item->program->djs) {
+    $dj_list = implode(', ', _station_schedule_program_load_djs($item->program->nid));
+    $output .= "<div class='station-sch-djs'>{$dj_list}</div>";
   }
   $output .= "</div>\n";
-  return l($output, 'node/'. $program->nid, NULL, NULL, NULL, NULL, TRUE);
+  return l($output, 'node/'. $item->program->nid, NULL, NULL, NULL, NULL, TRUE);
 }
 
 
