Index: schedule/station_schedule.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/schedule/station_schedule.install,v
retrieving revision 1.29
diff -u -p -r1.29 station_schedule.install
--- schedule/station_schedule.install	28 Nov 2009 22:06:44 -0000	1.29
+++ schedule/station_schedule.install	9 Jul 2010 05:10:22 -0000
@@ -137,6 +137,20 @@ function station_schedule_schema() {
         'not null' => TRUE,
         'default' => 0,
       ),
+      'start_hour' => array(
+        'description' => t('Programming start time in hours.'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'end_hour' => array(
+        'description' => t('Programming end time in hours.'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 24,
+      ),
       'streams' => array(
         'description' => t('Web stream URLs.'),
         'type' => 'text',
@@ -513,3 +527,13 @@ function station_schedule_update_6002() 
 
   return array();
 }
+
+/**
+ * Adds programming start times and end times to station schedules.
+ */
+function station_schedule_update_6003() {
+  $ret = array();
+  db_add_field($ret, 'station_schedule', 'start_hour', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+  db_add_field($ret, 'station_schedule', 'end_hour', array('type' => 'int', 'not null' => TRUE, 'default' => 24));
+  return $ret;
+}
Index: schedule/station_schedule.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/schedule/station_schedule.module,v
retrieving revision 1.94
diff -u -p -r1.94 station_schedule.module
--- schedule/station_schedule.module	28 Nov 2009 23:26:57 -0000	1.94
+++ schedule/station_schedule.module	9 Jul 2010 05:10:22 -0000
@@ -272,6 +272,22 @@ function station_schedule_form($node) {
     '#options' => array(1 => t('1 Minute'), 5 => t('5 Minutes'), 15 => t('15 Minutes'), 30 => t('30 Minutes'), 60 => t('1 Hour'), 120 => t('2 Hours')),
     '#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 weirdness."),
   );
+  $form['settings']['start_hour'] = array(
+    '#type' => 'select',
+    '#title' => t('Programming start time'),
+    '#default_value' => isset($node->settings['start_hour']) ? $node->settings['start_hour'] : 0,
+    '#options' => station_schedule_hour_options('start'),
+    '#required' => TRUE,
+    '#description' => t("This is the time of day when your programming starts."),
+  );
+  $form['settings']['end_hour'] = array(
+    '#type' => 'select',
+    '#title' => t('Programming end time'),
+    '#default_value' => isset($node->settings['end_hour']) ? $node->settings['end_hour'] : 24,
+    '#options' => station_schedule_hour_options('end'),
+    '#required' => TRUE,
+    '#description' => t("This is the time of day when your programming ends. It allows for programming ending as late as noon the next day."),
+  );
   $form['settings']['unscheduled_message'] = array(
     '#type' => 'textfield',
     '#title' => t('No scheduled programming message'),
@@ -332,6 +348,56 @@ function station_schedule_form($node) {
   return $form;
 }
 
+/**
+ * Returns an array of possible programming start and end times.
+ */
+function station_schedule_hour_options($type) {
+  // If type is "start", we'll provide 12am-11pm. If type is "end", we'll provide 1am through noon the next day.
+  switch ($type) {
+    case 'start':
+      $earliest = 0;
+      $latest = 24;
+      break;
+
+    case 'end':
+      $earliest = 1;
+      $latest = 36;
+      break;
+
+    default:
+      return;
+  }
+  $hour_options = array();
+  for ($i = $earliest; $i < $latest; $i++) {
+    if ($i == 0 || $i == 24) {
+      $hour = '12';
+      $suffix = 'am';
+    }
+    elseif ($i == 12) {
+      $hour = '12';
+      $suffix = 'pm';
+    }
+    elseif ($i > 12) {
+      if ($i > 24) {
+        // This is during the morning of the next day, so subtract 24 and attach the suffix 'tomorrow'.
+        $hour = $i - 24;
+        $suffix = 'am ' . t('the next day');
+      }
+      else {
+        // This is after noon on the current day, so subtract 12.
+        $hour = $i - 12;
+        $suffix = 'pm';
+      }
+    }
+    else {
+      // This is during the morning of the current day.
+      $hour = $i;
+      $suffix = 'am';
+    }
+    $hour_options[$i] = $hour . ':00' . $suffix;
+  }
+  return $hour_options;
+}
 
 function theme_station_schedule_form_streams($form) {
   $header = array(t('Name'), t('Description'), t('URLs'));
@@ -349,6 +415,11 @@ function theme_station_schedule_form_str
  * Implementation of hook_validate().
  */
 function station_schedule_validate(&$node) {
+  # Make sure the selected programming start time is earlier than the selected end time.
+  if ($node->settings['start_hour'] > $node->settings['end_hour']) {
+    form_set_error("settings][start_hour", t('The start time must be earlier than the end time.'));
+  }
+
   foreach ($node->settings['streams'] as $key => $stream) {
     // Must have both a name and URL.
     if (empty($stream['name']) xor empty($stream['urls'])) {
@@ -396,13 +467,20 @@ function station_schedule_form_submit($f
  */
 function station_schedule_load($node) {
   $schedule = array();
+
+  // Load the settings.
+  $settings = db_fetch_array(db_query('SELECT increment, streams, unscheduled_message, start_hour, end_hour FROM {station_schedule} WHERE nid = %d', $node->nid));
+
   // 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_hour = $settings['start_hour'] * 60;
+    $start = $day * MINUTES_IN_DAY + $start_hour;
+    $end_hour = $settings['end_hour'] * 60;
+    $finish = $day * MINUTES_IN_DAY + $end_hour;
+
     $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
@@ -417,8 +495,6 @@ function station_schedule_load($node) {
     }
   }
 
-  // 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'] = array();
     foreach ($streams as $key => $stream) {
@@ -925,7 +1001,9 @@ function station_schedule_week_page($nod
 
   // First column is hours.
   $row[0] = array('id' => 'station-sch-hours', 'data' => '');
-  for ($hour = 0; $hour < 24; $hour++) {
+  // Load the settings.
+  $settings = db_fetch_array(db_query('SELECT increment, streams, unscheduled_message, start_hour, end_hour FROM {station_schedule} WHERE nid = %d', $node->nid));
+  for ($hour = $settings['start_hour']; $hour < $settings['end_hour']; $hour++) {
     $row[0]['data'] .= theme('station_schedule_hour', $hour);
   }
 
@@ -935,8 +1013,8 @@ function station_schedule_week_page($nod
     $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 + ($settings['start_hour'] * 60);
+    $day_finish = (($day) * MINUTES_IN_DAY) + ($settings['end_hour'] * 60);
     foreach ($items as $item) {
       // Display blocks for unscheduled time periods
       if ($last_finish != $item->start) {
