Title: SF.net SVN: mrbs:[2435] mrbs/branches/flexible_day_end/web
Revision
2435
Author
cimorrison
Date
2012-09-25 09:19:29 +0000 (Tue, 25 Sep 2012)

Log Message

Blanked out time slots that don't exist from the day and week views, ie the time slots that start in the missing hour when the clocks go forward on the transition to DST.

Modified Paths

Diff

Modified: mrbs/branches/flexible_day_end/web/Themes/classic126/styling.inc (2434 => 2435)


--- mrbs/branches/flexible_day_end/web/Themes/classic126/styling.inc	2012-09-19 17:17:59 UTC (rev 2434)
+++ mrbs/branches/flexible_day_end/web/Themes/classic126/styling.inc	2012-09-25 09:19:29 UTC (rev 2435)
@@ -30,6 +30,7 @@
 $main_table_body_v_border_color = $main_table_body_h_border_color; // border colour for day/week/month tables - body, vertical
 $main_table_month_color         = "#ffffff";    // background colour for days in the month view
 $main_table_month_invalid_color = "#d1d9de";    // background colour for invalid days in the month view
+$main_table_slot_invalid_color  = "#d1d9de";    // ba;;    // background colour for invalid days in the month viewy, verticalthe transition to DST.
��.z+������ /z+p����@����k�-z+6 ��!�!���������x��.z+p�������-z+��-z+����`��-z+O������R/z+u��-z+�R/z+شR/z+��R/z+��-z+x��.z+p����@����k�-z+�!�!���������H��.z+P�������-z+��-z+����`��-z+O����@����8����8�-z+�p������u��-z+��-z+P���� ����k�-z+GHIJKMNOP���������HE�.z+��������-z+��-z+����0�R/z+u��-z+��.z+�y�.z+�R/z+شR/z+��R/z+��-z+HE�.z+�����0����k�-z+8E�.z+�����`����k�-z+(E�.z+����������k�-z+E�.z+����������k�-z+ ��R/z+u��-z+��R/z+@�����Ȃ.z+e��-z+شR/z+`����yȂ.z+e��-z+�R/z+�����ZȂ.z+e��-z+�t�.z+��.z+�y�.z+�R/z+���.z+شR/z+��R/z+��-z+8�-z+=N.z+�����p �.z+@��������k�-z+5678:<=>?@BD����������=K.z+�����u��-z+�-z+�����=N.z+e��-z+�-z+�_@f�S Q��l���S.z+������=K.z+P���� ����k�-z+u]�� 4Q��U^Qʉ��u������*ēv���������H�.z+�S.z+�������/z+��/z+�&Q.z+O���������8�����������.z+u��-z+���.z+������/z+Е���`��������������/z+�����ckground colour for invalid slots in the day and week views $main_table_labels_back_color = "#fff0f0"; // background colour for the row labels column // border colours for the main table when it is printed. These are used by mrbs-print.css.php

Modified: mrbs/branches/flexible_day_end/web/Themes/default/styling.inc (2434 => 2435)


--- mrbs/branches/flexible_day_end/web/Themes/default/styling.inc	2012-09-19 17:17:59 UTC (rev 2434)
+++ mrbs/branches/flexible_day_end/web/Themes/default/styling.inc	2012-09-25 09:19:29 UTC (rev 2435)
@@ -30,6 +30,7 @@
 $main_table_body_v_border_color = $body_background_color; // border colour for day/week/month tables - body, vertical
 $main_table_month_color         = "#ffffff";    // background colour for days in the month view
 $main_table_month_invalid_color = "#d1d9de";    // background colour for invalid days in the month view
+$main_table_slot_invalid_color  = "#d1d9de";    // background colour for invalid slots in the day and week views
 $main_table_labels_back_color   = $header_back_color;     // background colour for the row labels column
 
 // border colours for the main table when it is printed.     These are used by mrbs-print.css.php

Modified: mrbs/branches/flexible_day_end/web/css/mrbs.css.php (2434 => 2435)


--- mrbs/branches/flexible_day_end/web/css/mrbs.css.php	2012-09-19 17:17:59 UTC (rev 2434)
+++ mrbs/branches/flexible_day_end/web/css/mrbs.css.php	2012-09-25 09:19:29 UTC (rev 2435)
@@ -210,6 +210,7 @@
 .dwm_main#day_main th.first_last {width: <?php echo $column_row_labels_width ?>%}
 .dwm_main#week_main th {width: <?php echo $column_week ?>%}
 .dwm_main#week_main th.first_last {width: <?php echo $column_row_labels_width ?>%; vertical-align: bottom}
+.dwm_main td.invalid {background-color: <?php echo $main_table_slot_invalid_color ?>};
 .dwm_main#month_main th {width: <?php echo $column_month ?>%}
 .dwm_main#month_main td {border-top:  <?php echo $main_table_cell_border_width ?>px solid <?php echo $main_table_body_v_border_color ?>}
 .dwm_main#month_main td.valid   {background-color: <?php echo $main_table_month_color ?>}

Modified: mrbs/branches/flexible_day_end/web/functions.inc (2434 => 2435)


--- mrbs/branches/flexible_day_end/web/functions.inc	2012-09-19 17:17:59 UTC (rev 2434)
+++ mrbs/branches/flexible_day_end/web/functions.inc	2012-09-25 09:19:29 UTC (rev 2435)
@@ -1409,6 +1409,96 @@
 }
 
 
+// Compares two nominal dates which are indexed by'hours', 'minutes', 'seconds', 
+// 'mon', 'mday' and 'year', ie as in the ouput of getdate().  Returns -1 if the
+// first date is before the second, 0 if they are equal and +1 if the first date
+// is after the second.   NULL if a comparison can't be done.
+//
+// (Note that internally the function uses gmmktime() so the parameters do not
+// have to represent valid values.   For example you could pass '32' for day and
+// that would be interpreted as 4 days after '28'.)
+function nominal_date_compare($d1, $d2)
+{
+  // We compare the dates using gmmktime() because we are trying to compare nominal
+  // dates and so do not want DST transitions
+  $t1 = gmmktime($d1['hours'], $d1['minutes'], $d1['seconds'],
+                 $d1['mon'], $d1['mday'], $d1['year']);
+  $t2 = gmmktime($d2['hours'], $d2['minutes'], $d2['seconds'],
+                 $d2['mon'], $d2['mday'], $d2['year']);
+  if ($t1 < $t2)
+  {
+    return -1;
+  }
+  elseif ($t1 == $t2)
+  {
+    return 0;
+  }
+  else
+  {
+    return 1;
+  }
+}
+
+
+// Checks whether the nominal time given is a valid date and time with respect to
+// DST transitions.   When entering DST there is a set of times that don't exist, for
+// example from 0200 to 0259 in Europe/London.
+function is_valid_datetime($hour, $minute, $second, $month, $day, $year)
+{
+  global $timezone;
+  
+  // If the day before is in DST then the datetime must be valid, because
+  // you only get the gap when entering DST.
+  $dayBefore = mktime($hour, $minute, $second, $month, $day-1, $year);
+  if (date('I', $dayBefore))
+  {
+    return TRUE;
+  }
+  // The day before is not in DST.   If the day after is also not in DST,
+  // then there can have been no transition, so again the datetime must be valid.
+  $dayAfter = mktime($hour, $minute, $second, $month, $day+1, $year);
+  if (!date('I', $dayAfter))
+  {
+    return TRUE;
+  }
+  // We are in a transition into DST, so we need to check more carefully.
+  // However we can only do this efficiently in PHP 5.3.0 or greater
+  if (version_compare(PHP_VERSION, '5.3.0') < 0)
+  {
+    return NULL;
+  }
+  // Get the transition data (we assume there is one and only one transition),
+  // in particular the time at which the transition happens and the new offset
+  $thisDateTimeZone = new DateTimeZone($timezone);
+  $transitions = $thisDateTimeZone->getTransitions($dayBefore, $dayAfter);
+  // According to my reading of the PHP manual, getTransitions() should return
+  // all transitions between the start and end date.   However what it seems to do
+  // is return an array consisting of the time data for the start date followed by
+  // the transition data.   So as a precaution we take the last element of the array
+  // (we were only expecting one element, but seem to get two).
+  $transition = array_pop($transitions);
+  // If we failed for some reason to get any transition data, return NULL
+  if (!isset($transition))
+  {
+    return NULL;
+  }
+  
+  // Get the old offset and work out how many seconds the clocks change by
+  $beforeDateTime = new DateTime(date('c', $dayBefore), $thisDateTimeZone);
+  $change = $transition['offset'] - $beforeDateTime->getOffset();
+  
+  // See if the nominal date falls outside the gap
+  $lastValidSecond = getdate($transition['ts'] - 1);
+  $lastInvalidSecond = $lastValidSecond;
+  $lastInvalidSecond['seconds'] += $change;
+  $thisDate = array('hours' => $hour, 'minutes' => $minute, 'seconds' => $second,
+                    'mon' => $month, 'mday' => $day, 'year' => $year);
+                  
+  return ((nominal_date_compare($thisDate, $lastValidSecond) <= 0) || 
+          (nominal_date_compare($thisDate, $lastInvalidSecond) > 0));
+}
+
+
 // Returns TRUE if $t is in that part of daylight saving time that will have
 // the same nominal time as another timestamp shortly after the DST transition.
 // For example, will return TRUE for the $t equivalent to the first occurence

Modified: mrbs/branches/flexible_day_end/web/functions_table.inc (2434 => 2435)


--- mrbs/branches/flexible_day_end/web/functions_table.inc	2012-09-19 17:17:59 UTC (rev 2434)
+++ mrbs/branches/flexible_day_end/web/functions_table.inc	2012-09-25 09:19:29 UTC (rev 2435)
@@ -252,7 +252,7 @@
 
 
 
-function cell_html($cell, $query_strings)
+function cell_html($cell, $query_strings, $is_valid = TRUE)
 {
   // draws a single cell in the main table of the day and week views
   //
@@ -286,6 +286,9 @@
   //    ['new_periods']   the string to be used for an empty cell if using periods
   //    ['new_times']     the string to be used for an empty cell if using times
   //    ['booking']       the string to be used for a full cell
+  //
+  // $is_valid specifies whether the slot actually exists or is one of the non-existent
+  // slots in the transition to DST
     
   global $main_cell_height, $main_table_cell_border_width;
   global $area, $year, $month, $timetohighlight;
@@ -492,7 +495,7 @@
     }
     else
     {
-      $c = "new";
+      $c = ($is_valid) ? "new" : "invalid";
     }
     
     // Don't put in a <td> cell if the slot is booked and there's no description.
@@ -507,16 +510,20 @@
       // If the room isn't booked then allow it to be booked
       if (!isset($id))
       {
-        $html .= "<div class=\"celldiv slots1\">\n";  // a bookable slot is only one unit high
-        $html .= "<a href="" . 
-                 (($enable_periods) ? $query_strings['new_periods'] : $query_strings['new_times']) . 
-                 "\">\n";
-        if ($show_plus_link)
+        // Don't provide a link if the slot doesn't really exist
+        if ($is_valid)
         {
-          $html .= "<img src="" alt=\"New\" width=\"10\" height=\"10\">\n";
+          $html .= "<div class=\"celldiv slots1\">\n";  // a bookable slot is only one unit high
+          $html .= "<a href="" . 
+                   (($enable_periods) ? $query_strings['new_periods'] : $query_strings['new_times']) . 
+                   "\">\n";
+          if ($show_plus_link)
+          {
+            $html .= "<img src="" alt=\"New\" width=\"10\" height=\"10\">\n";
+          }
+          $html .= "</a>\n";
+          $html .= "</div>\n";
         }
-        $html .= "</a>\n";
-        $html .= "</div>\n";
       }
       else                 // if it is booked then show the booking
       {
@@ -722,6 +729,13 @@
 
   $am7 = get_start_first_slot($month, $day, $year);
   $pm7 = get_start_last_slot($month, $day, $year);
+  
+  // Work out whether there's a possibility that a time slot is invalid,
+  // in other words whether the booking day includes a transition into DST.
+  // If we know that there's no transition into DST then all slots are
+  // definitely valid and this saves us bothering to do the detailed calculations
+  // of which slots are invalid.
+  $is_definitely_valid = cross_dst($am7, $pm7) >= 0;
             
   // We want to build an array containing all the data we want to show
   // and then spit it out. 
@@ -894,10 +908,17 @@
       $room_id = $row['id']; 
       $room_cell_link = "week.php?year=$year&amp;month=$month&amp;day=$day&amp;area=$area&amp;room=$room_id";
       $tbody .= room_cell_html($row, $room_cell_link);
+      $is_valid = array();
       for ($s = $morning_slot_seconds;
            $s <= $evening_slot_seconds;
            $s += $resolution)
       {
+        // Work out whether this timeslot is valid and save the result, so that we
+        // don't have to repeat the calculation for every room
+        if (!isset($is_valid[$s]))
+        {
+          $is_valid[$s] = $is_definitely_valid || is_valid_datetime(0, 0, $s, $month, $day, $year);
+        }
         // set up the query strings to be used for the link in the cell
         $query_strings = get_query_strings($area, $room_id, $month, $day, $year, $s);
 
@@ -906,7 +927,7 @@
         {
           $today[$room_id][$day][$s] = array();  // to avoid an undefined index NOTICE error
         }
-        $tbody .= cell_html($today[$room_id][$day][$s], $query_strings);
+        $tbody .= cell_html($today[$room_id][$day][$s], $query_strings, $is_valid[$s]);
       }  // end for (looping through the times)
       if ( FALSE != $row_labels_both_sides )
       {
@@ -937,7 +958,7 @@
       }
       $tbody .= "<tr class=\"$class\">\n";
       $tbody .= time_cell_html($s, $url);
-  
+      $is_valid = $is_definitely_valid || is_valid_datetime(0, 0, $s, $month, $day, $year);
       // Loop through the list of rooms we have for this area
       while (list($key, $room_id) = each($rooms))
       {
@@ -949,7 +970,7 @@
         {
           $today[$room_id][$day][$s] = array();  // to avoid an undefined index NOTICE error
         }
-        $tbody .= cell_html($today[$room_id][$day][$s], $query_strings);
+        $tbody .= cell_html($today[$room_id][$day][$s], $query_strings, $is_valid);
       }
       
       // next lines to display times on right side
@@ -1022,6 +1043,12 @@
   {
     $am7[$j] = get_start_first_slot($month, $day_start_week+$j, $year);
     $pm7[$j] = get_start_last_slot($month, $day_start_week+$j, $year);
+    // Work out whether there's a possibility that a time slot is invalid,
+    // in other words whether the booking day includes a transition into DST.
+    // If we know that there's no transition into DST then all slots are
+    // definitely valid and this saves us bothering to do the detailed calculations
+    // of which slots are invalid.
+    $is_definitely_valid[$j] = cross_dst($am7[$j], $pm7[$j]) >= 0;
   }
   unset($j);  // Just so that we pick up any accidental attempt to use it later
 
@@ -1099,6 +1126,7 @@
     // with times along the top and days of the week down the side
     $column_width = (int)(95 / $n_time_slots);
     $header_inner .= "<th class=\"first_last\">" . get_vocab("date") . ":</th>";
+    
     for ($s = $morning_slot_seconds;
          $s <= $evening_slot_seconds;
          $s += $resolution)
@@ -1214,6 +1242,7 @@
              $s <= $evening_slot_seconds;
              $s += $resolution)
         {
+          $is_valid = $is_definitely_valid[$thisday] || is_valid_datetime(0, 0, $s, $wmonth, $wday, $wyear);
           // set up the query strings to be used for the link in the cell
           $query_strings = get_query_strings($area, $room, $wmonth, $wday, $wyear, $s);
 
@@ -1222,7 +1251,7 @@
           {
             $week_map[$room][$thisday][$s] = array();  // to avoid an undefined index NOTICE error
           }
-          $tbody .= cell_html($week_map[$room][$thisday][$s], $query_strings);
+          $tbody .= cell_html($week_map[$room][$thisday][$s], $query_strings, $is_valid);
         }  // end looping through the time slots
         if ( FALSE != $row_labels_both_sides )
         {
@@ -1273,6 +1302,7 @@
           $wday = date("d", $wt);
           $wmonth = date("m", $wt);
           $wyear = date("Y", $wt);
+          $is_valid = $is_definitely_valid[$thisday] || is_valid_datetime(0, 0, $s, $wmonth, $wday, $wyear);
           $query_strings = get_query_strings($area, $room, $wmonth, $wday, $wyear, $s);
      
           // and then draw the cell
@@ -1280,7 +1310,7 @@
           {
             $week_map[$room][$thisday][$s] = array();  // to avoid an undefined index NOTICE error
           }
-          $tbody .= cell_html($week_map[$room][$thisday][$s], $query_strings);
+          $tbody .= cell_html($week_map[$room][$thisday][$s], $query_strings, $is_valid);
         }
   
       }    // for loop
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to