Revision: 2701
https://sourceforge.net/p/mrbs/code/2701/
Author: cimorrison
Date: 2013-02-15 14:41:24 +0000 (Fri, 15 Feb 2013)
Log Message:
-----------
Fixed various issues with booking days spanning midnight, including a problem
with checking the All Day checkbox (see SF Bugs #236 part (3))
Modified Paths:
--------------
mrbs/trunk/web/edit_entry.php
mrbs/trunk/web/edit_entry_handler.php
mrbs/trunk/web/functions.inc
mrbs/trunk/web/functions_table.inc
Modified: mrbs/trunk/web/edit_entry.php
===================================================================
--- mrbs/trunk/web/edit_entry.php 2013-02-15 13:02:30 UTC (rev 2700)
+++ mrbs/trunk/web/edit_entry.php 2013-02-15 14:41:24 UTC (rev 2701)
@@ -84,19 +84,28 @@
// Returns the booking date for a given time. If the booking day spans
midnight and
// $t is in the interval between midnight and the end of the day then the
booking date
// is really the day before.
-function getbookingdate($t)
+//
+// If $is_end is set then this is the end time and so if the booking day
happens to
+// last exactly 24 hours, when there will be two possible answers, we want the
later
+// one.
+function getbookingdate($t, $is_end=FALSE)
{
global $eveningends, $eveningends_minutes, $resolution;
$date = getdate($t);
$t_secs = (($date['hours'] * 60) + $date['minutes']) * 60;
- $e_secs = ((($eveningends * 60) + $eveningends_minutes) * 60) + $resolution;
- if (day_past_midnight() && ($t_secs <= $e_secs))
+ $e_secs = (((($eveningends * 60) + $eveningends_minutes) * 60) +
$resolution) % (24*60*60);
+
+ if (day_past_midnight())
{
- $date = getdate(mktime($date['hours'], $date['minutes'], $date['seconds'],
- $date['mon'], $date['mday'] -1, $date['year']));
- $date['hours'] += 24;
+ if (($t_secs < $e_secs) ||
+ (($t_secs == $e_secs) && $is_end))
+ {
+ $date = getdate(mktime($date['hours'], $date['minutes'],
$date['seconds'],
+ $date['mon'], $date['mday'] -1, $date['year']));
+ $date['hours'] += 24;
+ }
}
return $date;
@@ -301,7 +310,7 @@
{
global $end_time, $areas, $area_id, $periods, $multiday_allowed;
- $date = getbookingdate($end_time);
+ $date = getbookingdate($end_time, TRUE);
$current_s = (($date['hours'] * 60) + $date['minutes']) * 60;
echo "<div id=\"div_end_date\">\n";
Modified: mrbs/trunk/web/edit_entry_handler.php
===================================================================
--- mrbs/trunk/web/edit_entry_handler.php 2013-02-15 13:02:30 UTC (rev
2700)
+++ mrbs/trunk/web/edit_entry_handler.php 2013-02-15 14:41:24 UTC (rev
2701)
@@ -339,7 +339,8 @@
// $returl will end up taking us back to the day we started on
if (day_past_midnight())
{
- if ($start_seconds < (((($eveningends * 60) + $eveningends_minutes) *60) +
$resolution))
+ $end_last = (((($eveningends * 60) + $eveningends_minutes) *60) +
$resolution) % (24*60*60);
+ if ($start_seconds < $end_last)
{
$start_seconds += 24*60*60;
$day_before = getdate(mktime(0, 0, 0, $start_month, $start_day-1,
$start_year));
Modified: mrbs/trunk/web/functions.inc
===================================================================
--- mrbs/trunk/web/functions.inc 2013-02-15 13:02:30 UTC (rev 2700)
+++ mrbs/trunk/web/functions.inc 2013-02-15 14:41:24 UTC (rev 2701)
@@ -453,13 +453,17 @@
}
-// Returns TRUE if $evening_ends is on the day after $morning_starts
+// Returns TRUE if the end of the last slot is on the day after the beginning
+// of the first slot
function day_past_midnight()
{
- global $morningstarts, $morningstarts_minutes, $eveningends,
$eveningends_minutes;
+ global $morningstarts, $morningstarts_minutes, $eveningends,
$eveningends_minutes, $resolution;
- return hm_before(array('hours' => $eveningends, 'minutes' =>
$eveningends_minutes),
- array('hours' => $morningstarts, 'minutes' =>
$morningstarts_minutes));
+ $start_first_slot = (($morningstarts * 60) + $morningstarts_minutes) * 60;
+ $end_last_slot = ((($eveningends * 60) + $eveningends_minutes) * 60) +
$resolution;
+ $end_last_slot = $end_last_slot % (24*60*60);
+
+ return ($end_last_slot <= $start_first_slot);
}
@@ -477,10 +481,11 @@
// Gets the UNIX timestamp for the start of the last slot on the given day
function get_start_last_slot($month, $day, $year)
{
- global $eveningends, $eveningends_minutes;
+ global $morningstarts, $morningstarts_minutes, $eveningends,
$eveningends_minutes;
// Work out if $evening_ends is really on the next day
- if (day_past_midnight())
+ if (hm_before(array('hours' => $eveningends, 'minutes' =>
$eveningends_minutes),
+ array('hours' => $morningstarts, 'minutes' =>
$morningstarts_minutes)))
{
$day++;
}
Modified: mrbs/trunk/web/functions_table.inc
===================================================================
--- mrbs/trunk/web/functions_table.inc 2013-02-15 13:02:30 UTC (rev 2700)
+++ mrbs/trunk/web/functions_table.inc 2013-02-15 14:41:24 UTC (rev 2701)
@@ -643,15 +643,16 @@
global $morningstarts, $morningstarts_minutes, $eveningends,
$eveningends_minutes;
global $resolution;
- $morning = ($morningstarts * 60) + $morningstarts_minutes; // minutes
- $evening = ($eveningends * 60) + $eveningends_minutes; // minutes
+ $seconds_per_day = 24*60*60;
+ $start_first = (($morningstarts * 60) + $morningstarts_minutes) * 60;
// seconds
+ $end_last = ((($eveningends * 60) + $eveningends_minutes) * 60) +
$resolution; // seconds
+ $end_last = $end_last % $seconds_per_day;
if (day_past_midnight())
{
- $evening += 24*60;
+ $end_last += $seconds_per_day;
}
- $difference = ($evening - $morning) * 60; // seconds
- $n_slots = ($difference/$resolution) + 1;
-
+ $n_slots = ($end_last - $start_first)/$resolution;
+
return $n_slots;
}
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits