Index: station_schedule.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/schedule/station_schedule.install,v
retrieving revision 1.16
diff -u -r1.16 station_schedule.install
--- station_schedule.install  1 Nov 2007 17:52:11 -0000 1.16
+++ station_schedule.install  3 Nov 2007 13:51:24 -0000
@@ -13,6 +13,8 @@
         CREATE TABLE {station_schedule} (
           `nid` int unsigned NOT NULL default '0',
           `increment` int unsigned NOT NULL default '0',
+          `schedule_start` int unsigned NOT NULL default '0', 
+          `schedule_finish` int unsigned NOT NULL default '24',          
           `streams` longtext,
           `unscheduled_message` VARCHAR(255) NOT NULL default '',
           PRIMARY KEY(`nid`)
@@ -377,3 +379,22 @@
   }
   return $ret;
 }
+
+/**
+ * Add start and end times to schedules.
+ */
+function station_schedule_update_5204() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {station_schedule} ADD COLUMN `schedule_start` int unsigned AFTER `increment`");      
+      $ret[] = update_sql("ALTER TABLE {station_schedule} ADD COLUMN `schedule_finish` int unsigned AFTER `schedule_start`");      
+
+      db_query("UPDATE {station_schedule} SET schedule_start = '0'");
+      db_query("UPDATE {station_schedule} SET schedule_finish = '24'");
+      
+      break;
+  }
+  return $ret;
+}
Index: station_schedule.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/schedule/station_schedule.module,v
retrieving revision 1.58
diff -u -r1.58 station_schedule.module
--- station_schedule.module 1 Nov 2007 17:52:11 -0000 1.58
+++ station_schedule.module 3 Nov 2007 16:19:38 -0000
@@ -206,6 +206,24 @@
     '#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>Caution:</strong> Increasing this value on an existing schedule will probably cause wierdness."),
   );
+  $hour_options = array();
+  for ($hour = 0; $hour <= 24; $hour++) {
+    $hour_options[] = $hour;
+  }  
+  $form['settings']['schedule_start'] = array(
+    '#type' => 'select',
+    '#title' => t('Schedule start'),
+    '#default_value' => isset($node->settings['schedule_start']) ? $node->settings['schedule_start'] : 0,
+    '#options' => $hour_options,
+    '#description' => t("The hour of the day at which the schedule begins."),
+  );  
+  $form['settings']['schedule_finish'] = array(
+    '#type' => 'select',
+    '#title' => t('Schedule finish'),
+    '#default_value' => isset($node->settings['schedule_finish']) ? $node->settings['schedule_finish'] : 24,
+    '#options' => $hour_options,
+    '#description' => t("The hour of the day at which the schedule ends."),
+  );  
   $form['settings']['unscheduled_message'] = array(
     '#type' => 'textfield',
     '#title' => t('No scheduled programming message'),
@@ -301,6 +319,10 @@
       }
     }
   }
+  // schedule end time must be later than start time
+  if ($node->settings['schedule_finish'] <= $node->settings['schedule_start']) {
+    form_set_error("settings][schedule_finish", t('Schedule end time must be later than start time.'));    
+  }
 }
 
 /**
@@ -324,15 +346,35 @@
  * Implementation of hook_load().
  */
 function station_schedule_load($node) {
+
+  // Load the settings.
+  $settings = db_fetch_array(db_query('SELECT increment, schedule_start, schedule_finish, streams, unscheduled_message FROM {station_schedule} WHERE nid = %d', $node->nid));
+  if (isset($settings['streams']) && $streams = unserialize($settings['streams'])) {
+    $settings['streams'] = $streams;
+  }
+  else {
+    $settings['streams'] = array();
+  }
+
+  // Load the schedule.
   $schedule = array();
+  // get the start and end times of the schedule
+  $schedule_start   = $settings['schedule_start'];
+  $schedule_finish  = $settings['schedule_finish'];
+  if ($schedule_finish < $schedule_start) {
+    $schedule_finish += 24;
+  } // for wrapping: to come later
+  
   // Use station_day_name() for the day ordering in case Sunday isn't the
   // first day of the week.
   foreach (station_day_name() as $day => $name) {
     $schedule[$day] = array();
 
-    $start = $day * MINUTES_IN_DAY;
-    $finish = $start + MINUTES_IN_DAY;
+    $start = $day * MINUTES_IN_DAY + $schedule_start * 60;
+    $finish = $day * MINUTES_IN_DAY + $schedule_finish * 60;
+    
     $result = db_query('SELECT * FROM {station_schedule_item} i WHERE i.schedule_nid = %d AND i.finish > %d AND i.start < %d ORDER BY i.start', $node->nid, $start, $finish);
+
     while ($s = db_fetch_object($result)) {
       // If a show spans a day, limit its start and finish times to be with-in
       // the day.
@@ -346,15 +388,6 @@
     }
   }
 
-  // Load the settings.
-  $settings = db_fetch_array(db_query('SELECT increment, streams, unscheduled_message FROM {station_schedule} WHERE nid = %d', $node->nid));
-  if (isset($settings['streams']) && $streams = unserialize($settings['streams'])) {
-    $settings['streams'] = $streams;
-  }
-  else {
-    $settings['streams'] = array();
-  }
-
   return array(
     'settings' => $settings,
     'schedule' => $schedule,
@@ -365,7 +398,7 @@
  * Implementation of hook_insert().
  */
 function station_schedule_insert($node) {
-  db_query("INSERT INTO {station_schedule} (nid, increment, streams, unscheduled_message) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->settings['increment'], serialize($node->settings['streams']), $node->settings['unscheduled_message']);
+  db_query("INSERT INTO {station_schedule} (nid, increment, schedule_start, schedule_finish, streams, unscheduled_message) VALUES (%d, %d, %d, %d, '%s', '%s')", $node->nid, $node->settings['increment'], $node->settings['schedule_start'], $node->settings['schedule_finish'], serialize($node->settings['streams']), $node->settings['unscheduled_message']);
 }
 
 /**
@@ -381,7 +414,7 @@
  */
 function station_schedule_update($node) {
   db_query("DELETE FROM {station_schedule} WHERE nid = %d", $node->nid);
-  db_query("INSERT INTO {station_schedule} (nid, increment, streams, unscheduled_message) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->settings['increment'], serialize($node->settings['streams']), $node->settings['unscheduled_message']);
+  db_query("INSERT INTO {station_schedule} (nid, increment, schedule_start, schedule_finish, streams, unscheduled_message) VALUES (%d, %d, %d, %d, '%s', '%s')", $node->nid, $node->settings['increment'], $node->settings['schedule_start'], $node->settings['schedule_finish'], serialize($node->settings['streams']), $node->settings['unscheduled_message']);
 }
 
 function station_schedule_admin_settings() {
@@ -924,6 +957,14 @@
   drupal_add_css(drupal_get_path('module', 'station_schedule') .'/station_schedule.css');
   drupal_set_title(check_plain($node->title));
 
+  // get the start and end times of the schedule  
+  $schedule_start   = $node->settings['schedule_start'];
+  $schedule_finish  = $node->settings['schedule_finish'];
+  
+  if ($schedule_finish < $schedule_start) {
+    $schedule_finish += 24;
+  } // for wrapping: to come later
+
   $header = array();
   $row = array();
   foreach ($node->schedule as $day => $items) {
@@ -931,8 +972,9 @@
     $row[$day] = '';
 
     // The last finish pointer starts at the beginning of the day.
-    $last_finish = $day * MINUTES_IN_DAY;
-    $day_finish = ($day + 1) * MINUTES_IN_DAY;
+    $last_finish = $day * MINUTES_IN_DAY + $schedule_start * 60;
+    $day_finish  = $day * MINUTES_IN_DAY + $schedule_finish * 60;
+    
     foreach ($items as $item) {
       // Display blocks for unscheduled time periods
       if ($last_finish != $item->start) {
@@ -1212,10 +1254,17 @@
     $header[0] = array('data' => t('Time'));
     $row = array();
 
+  // get the start and end times of the schedule
+    $schedule_start   = $node->settings['schedule_start'];
+    $schedule_finish  = $node->settings['schedule_finish'];
+    if ($schedule_finish < $schedule_start) {
+      $schedule_finish += 24;
+    } // for wrapping: to come later
+
     // First column is hours.
     $row[0]['id'] = 'station-sch-hours';
-    for ($hour = 0; $hour < 24; $hour++) {
-      $row[0]['data'] .= theme('station_schedule_hour', $hour);
+    for ($hour = $schedule_start; $hour < $schedule_finish; $hour++) {
+      $row[0]['data'] .= theme('station_schedule_hour', $hour % 24);
     }
 
     // Then a column for each day of the week.
@@ -1224,8 +1273,8 @@
       $row[$day + 1]['data'] = '';
 
       // The last finish pointer starts at the beginning of the day.
-      $last_finish = $day * MINUTES_IN_DAY;
-      $day_finish = ($day + 1) * MINUTES_IN_DAY;
+      $last_finish = $day * MINUTES_IN_DAY + $schedule_start * 60;
+      $day_finish  = $day * MINUTES_IN_DAY + $schedule_finish * 60;
       foreach ($items as $item) {
         // Display blocks for unscheduled time periods
         if ($last_finish != $item->start) {
