--- /home/joachim/public_html/drupal-5.1/custom modules/station/schedule/origXstation_schedule.module 
+++ /home/joachim/public_html/drupal-5.1/custom modules/station/schedule/station_schedule.module 
@@ -867,6 +867,20 @@
   drupal_set_title(t('Weekly Schedule'));
 
   $today = station_today();
+  
+  // get the earliest start time and latest finish time, in daily minutes
+  // !!!! these queries work directly on the databse in phpmyadmin,
+  // but appear to return the wrong sort of thing.
+  $earliest = db_query('SELECT MIN(mod( {start} ,1440)) FROM {station_schedule}');
+  $latest   = db_query('SELECT MAX(mod( {finish},1440)) FROM {station_schedule}');
+  // calculate start and end time in hours, rounded to complete hours
+  // eg turn 09:15 - 15:30 into 09:00 - 16:00
+  $hour_start   = ($earliest - $earliest % 60)/60;
+  $hour_finish  = ($latest   + ($latest % 60 != 0 ? 60 - $latest % 60 : 0))/60; 
+  
+  // hardcoding some numbers so the rest of it works
+  $hour_start   = 8;
+  $hour_finish  = 22;               
 
   // build the headers
   $cols = array('data' => t('Time'));
@@ -878,7 +892,7 @@
 
   $row = array();
   // put in a column of hours
-  for ($i = 0; $i < 24; $i++) {
+  for ($i = $hour_start; $i < $hour_finish; $i++) {  
     $cell .= theme('station_schedule_hour', $i);
   }
   $row[] = array('data' => $cell, 'id' => 'station-sch-hours');
@@ -886,8 +900,8 @@
   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;
+    $day_start = $i * 1440 + $hour_start * 60;
+    $day_finish = $i * 1440 + $hour_finish * 60;
     $last_finish = $day_start;
     foreach (station_schedule_load_day($i) as $s) {
       // display blocks for unscheduled time before this program
