Changeset:
        81c9eb134647
        
https://sourceforge.net/p/mrbs/hg-code/ci/81c9eb134647b685f7cad785a67bf973b064b016
Author:
        Campbell Morrison <[email protected]>
Date:
        Tue Jan 10 15:44:55 2017 +0000
Log message:

Fixed problem with default_duration not going past the end of a booking day.   
See SF Support Requests #116

diffstat:

 web/edit_entry.php |   3 +-
 web/functions.inc  |  69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 2 deletions(-)

diffs (92 lines):

diff -r 7a02bb005992 -r 81c9eb134647 web/edit_entry.php
--- a/web/edit_entry.php        Sat Jan 07 10:50:15 2017 +0000
+++ b/web/edit_entry.php        Tue Jan 10 15:44:55 2017 +0000
@@ -959,8 +959,7 @@
     
     $end_time = $start_time + $duration;
     // The end time can't be past the end of the booking day
-    $pm7 = get_start_last_slot($month, $day, $year);
-    $end_time = min($end_time, $pm7 + $resolution);
+    $end_time = fit_to_booking_day($end_time, $back=true);
   }
   
   $rep_id        = 0;
diff -r 7a02bb005992 -r 81c9eb134647 web/functions.inc
--- a/web/functions.inc Sat Jan 07 10:50:15 2017 +0000
+++ b/web/functions.inc Tue Jan 10 15:44:55 2017 +0000
@@ -574,6 +574,75 @@
 }
 
 
+function get_end_last_slot($month, $day, $year)
+{
+  global $resolution;
+  
+  return get_start_last_slot() + $resolution;
+}
+
+
+// Determines with a given timestamp is within a booking day, ie between the 
start of
+// the first slot and end of the last slot.   Returns a boolean.
+function is_in_booking_day($t)
+{
+  global $morningstarts, $morningstarts_minutes,
+         $eveningends, $eveningends_minutes,
+         $resolution;
+  
+  $start_day_secs = (($morningstarts * 60) + $morningstarts_minutes) * 60;
+  $end_day_secs = (((($eveningends * 60) + $eveningends_minutes) * 60) + 
$resolution) % SECONDS_PER_DAY;
+  
+  $date = getdate($t);
+  $t_secs = (($date['hours'] * 60) + $date['minutes']) * 60;
+  
+  if ($start_day_secs == $end_day_secs)
+  {
+    return true;
+  }
+  elseif (day_past_midnight())
+  {
+    return (($t_secs >= $start_day_secs) || ($t_secs <= $end_day_secs));
+  }
+  else
+  {
+    return (($t_secs >= $start_day_secs) && ($t_secs <= $end_day_secs));
+  }
+}
+
+
+// Force a timestamp $t to be on a booking day, either by moving it back to 
the end
+// of the previous booking day, or forward to the start of the next.
+function fit_to_booking_day($t, $back=true)
+{
+  if (is_in_booking_day($t))
+  {
+    return $t;
+  }
+  
+  $date = getdate($t);
+  // Remember that we need to cater for days that stretch beyond midnight.
+  if ($back)
+  {
+    $new_t = get_end_last_slot($date['mon'], $date['mday'], $date['year']);
+    if ($new_t > t)
+    {
+      $new_t = get_end_last_slot($date['mon'], $date['mday'] - 1, 
$date['year']);
+    }
+  }
+  else
+  {
+    $new_t = get_start_first_slot($date['mon'], $date['mday'], $date['year']);
+    if ($new_t < t)
+    {
+      $new_t = get_start_first_slot($date['mon'], $date['mday'] + 1, 
$date['year']);
+    }
+  }
+ 
+  return $new_t;
+}
+
+
 // Get the duration of an interval given a start time and end time.  Corrects 
for
 // DST changes so that the duration is what the user would expect to see.  For
 // example 12 noon to 12 noon crossing a DST boundary is 24 hours.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to