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

Log Message

Fixed bug introduced in last change when running on PHP < 5.3.0 (all times would be invalid)

Modified Paths

Diff

Modified: mrbs/branches/flexible_day_end/web/edit_entry.php (2435 => 2436)


--- mrbs/branches/flexible_day_end/web/edit_entry.php	2012-09-25 09:19:29 UTC (rev 2435)
+++ mrbs/branches/flexible_day_end/web/edit_entry.php	2012-09-25 11:06:12 UTC (rev 2436)
@@ -111,7 +111,7 @@
   // Get the current hour and minute and convert it into nominal (ie ignoring any
   // DST effects) seconds since the start of the day
   $date = getdate($time);
-  $current_t = (($date['hours'] * 60) + $date['minutes']) * 60;
+  $current_s = (($date['hours'] * 60) + $date['minutes']) * 60;
   
   if ($enable_periods)
   {
@@ -132,13 +132,13 @@
            " id=\"${prefix}seconds${area['id']}\" name=\"${prefix}seconds\" _onChange_=\"adjustSlotSelectors(this.form)\">\n";
   
   // Construct an array of times
-  $ts = array();
+  $s_array = array();
   if ($first <= $last)
   {
     // The simple case where the booking day is contained within the calendar day
-    for ($t = $first; $t <= $last; $t = $t + $resolution)
+    for ($s = $first; $s <= $last; $s += $resolution)
     {
-      $ts[] = $t;
+      $s_array[] = $s;
     }
   }
   else
@@ -146,28 +146,28 @@
     // The complex case where the booking day spans midnight.    In this case we have
     // to get the possible times from the start of the first slot after midnight to the
     // "last" time, and then from the "first" time to midnight
-    for ($t = $last%$resolution; $t <= $last; $t = $t + $resolution)
+    for ($s = $last%$resolution; $s <= $last; $s += $resolution)
     {
-      $ts[] = $t;
+      $s_array[] = $s;
     }
-    for ($t = $first; $t < 24*60*60; $t = $t + $resolution)
+    for ($s = $first; $s < 24*60*60; $s += $resolution)
     {
-      $ts[] = $t;
+      $s_array[] = $s;
     }
   }
   
-  foreach ($ts as $t)
+  foreach ($s_array as $s)
   {
-    $slot_string = ($enable_periods) ? $periods[intval(($t-$base)/60)] : hour_min($t);
-    $html .= "<option value=\"$t\"";
-    $html .= ($t == $current_t) ? " selected=\"selected\"" : "";
+    $slot_string = ($enable_periods) ? $periods[intval(($s-$base)/60)] : hour_min($s);
+    $html .= "<option value=\"$s\"";
+    $html .= ($s == $current_s) ? " selected=\"selected\"" : "";
     $html .= ">$slot_string</option>\n";
   }
   $html .= "</select>\n";
   // Add in a hidden input if the select is disabled but displayed
   if ($disabled && !$display_none)
   {
-    $html .= "<input type=\"hidden\" name=\"${prefix}seconds\" value=\"$current_t\">\n";
+    $html .= "<input type=\"hidden\" name=\"${prefix}seconds\" value=\"$current_s\">\n";
   }
   
   echo $html;

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


--- mrbs/branches/flexible_day_end/web/functions.inc	2012-09-25 09:19:29 UTC (rev 2435)
+++ mrbs/branches/flexible_day_end/web/functions.inc	2012-09-25 11:06:12 UTC (rev 2436)
@@ -1440,26 +1440,33 @@
 }
 
 
-// Checks whether the nominal time given is a valid date and time with respect to
+// Checks whether the nominal time given is an invalid 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)
+// Returns NULL if MRBS is unable to determine an answer, otherwise TRUE or FALSE (so
+// a simple equality test will default to a valid time if MRBS can't determine an answer)
+function is_invalid_datetime($hour, $minute, $second, $month, $day, $year, $tz=NULL)
 {
   global $timezone;
   
+  if (!isset($tz))
+  {
+    $tz = $timezone;  // default to the current 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;
+    return FALSE;
   }
   // 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;
+    return FALSE;
   }
   // 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
@@ -1469,7 +1476,7 @@
   }
   // 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);
+  $thisDateTimeZone = new DateTimeZone($tz);
   $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
@@ -1494,8 +1501,8 @@
   $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));
+  return ((nominal_date_compare($thisDate, $lastValidSecond) > 0) && 
+          (nominal_date_compare($thisDate, $lastInvalidSecond) <= 0));
 }
 
 

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


--- mrbs/branches/flexible_day_end/web/functions_table.inc	2012-09-25 09:19:29 UTC (rev 2435)
+++ mrbs/branches/flexible_day_end/web/functions_table.inc	2012-09-25 11:06:12 UTC (rev 2436)
@@ -252,7 +252,7 @@
 
 
 
-function cell_html($cell, $query_strings, $is_valid = TRUE)
+function cell_html($cell, $query_strings, $is_invalid = FALSE)
 {
   // draws a single cell in the main table of the day and week views
   //
@@ -287,7 +287,7 @@
   //    ['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
+  // $is_invalid 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;
@@ -495,7 +495,7 @@
     }
     else
     {
-      $c = ($is_valid) ? "new" : "invalid";
+      $c = ($is_invalid) ? "invalid" : "new";
     }
     
     // Don't put in a <td> cell if the slot is booked and there's no description.
@@ -511,7 +511,7 @@
       if (!isset($id))
       {
         // Don't provide a link if the slot doesn't really exist
-        if ($is_valid)
+        if (!$is_invalid)
         {
           $html .= "<div class=\"celldiv slots1\">\n";  // a bookable slot is only one unit high
           $html .= "<a href="" . 
@@ -732,10 +732,10 @@
   
   // 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;
+  // If we know that there's a transition into DST then some of the slots are
+  // going to be invalid.   Knowing whether or not there are possibly invalid slots
+  // saves us bothering to do the detailed calculations of which slots are invalid.
+  $is_possibly_invalid = cross_dst($am7, $pm7) < 0;
             
   // We want to build an array containing all the data we want to show
   // and then spit it out. 
@@ -908,16 +908,16 @@
       $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();
+      $is_invalid = 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
+        // Work out whether this timeslot is invalid and save the result, so that we
         // don't have to repeat the calculation for every room
-        if (!isset($is_valid[$s]))
+        if (!isset($is_invalid[$s]))
         {
-          $is_valid[$s] = $is_definitely_valid || is_valid_datetime(0, 0, $s, $month, $day, $year);
+          $is_invalid[$s] = $is_possibly_invalid && is_invalid_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);
@@ -927,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, $is_valid[$s]);
+        $tbody .= cell_html($today[$room_id][$day][$s], $query_strings, $is_invalid[$s]);
       }  // end for (looping through the times)
       if ( FALSE != $row_labels_both_sides )
       {
@@ -958,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);
+      $is_invalid = $is_possibly_invalid && is_invalid_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))
       {
@@ -970,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, $is_valid);
+        $tbody .= cell_html($today[$room_id][$day][$s], $query_strings, $is_invalid);
       }
       
       // next lines to display times on right side
@@ -1045,10 +1045,10 @@
     $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;
+    // If we know that there's a transition into DST then some of the slots are
+    // going to be invalid.   Knowing whether or not there are possibly invalid slots
+    // saves us bothering to do the detailed calculations of which slots are invalid.
+    $is_possibly_invalid[$j] = cross_dst($am7[$j], $pm7[$j]) < 0;
   }
   unset($j);  // Just so that we pick up any accidental attempt to use it later
 
@@ -1242,7 +1242,7 @@
              $s <= $evening_slot_seconds;
              $s += $resolution)
         {
-          $is_valid = $is_definitely_valid[$thisday] || is_valid_datetime(0, 0, $s, $wmonth, $wday, $wyear);
+          $is_invalid = $is_possibly_invalid[$thisday] && is_invalid_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);
 
@@ -1251,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, $is_valid);
+          $tbody .= cell_html($week_map[$room][$thisday][$s], $query_strings, $is_invalid);
         }  // end looping through the time slots
         if ( FALSE != $row_labels_both_sides )
         {
@@ -1302,7 +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);
+          $is_invalid = $is_possibly_invalid[$thisday] && is_invalid_datetime(0, 0, $s, $wmonth, $wday, $wyear);
           $query_strings = get_query_strings($area, $room, $wmonth, $wday, $wyear, $s);
      
           // and then draw the cell
@@ -1310,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, $is_valid);
+          $tbody .= cell_html($week_map[$room][$thisday][$s], $query_strings, $is_invalid);
         }
   
       }    // 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