Revision: 2965
https://sourceforge.net/p/mrbs/code/2965/
Author: cimorrison
Date: 2015-01-20 16:09:46 +0000 (Tue, 20 Jan 2015)
Log Message:
-----------
Fixed bug in calculation of periods in report summaries. See SF Support
Requests #667
Modified Paths:
--------------
mrbs/trunk/web/functions.inc
mrbs/trunk/web/report.php
Modified: mrbs/trunk/web/functions.inc
===================================================================
--- mrbs/trunk/web/functions.inc 2015-01-20 11:27:28 UTC (rev 2964)
+++ mrbs/trunk/web/functions.inc 2015-01-20 16:09:46 UTC (rev 2965)
@@ -305,6 +305,50 @@
}
+// Gets the interval in periods for a booking with $start_time and $end_time
+// Takes account of DST
+function getPeriodInterval($start_time, $end_time)
+{
+ global $periods;
+
+ $periods_per_day = count($periods);
+
+ $startDate = new DateTime();
+ $startDate->setTimestamp($start_time);
+ $endDate = new DateTime();
+ $endDate->setTimestamp($end_time);
+
+ // Set both dates to midnight so that we can compare them and get an integral
+ // number of days difference
+ $startDate->modify('00:00');
+ $endDate->modify('00:00');
+
+ // Calculate the difference in days
+ $interval = $startDate->diff($endDate);
+ $interval_days = $interval->format('%a');
+
+ if ($interval_days == 0)
+ {
+ // If the interval starts and ends on the same day, the we just calculate
the number
+ // of periods by calculating the number of minutes between the start and
end times.
+ $result = ($end_time - $start_time)/60;
+ }
+ else
+ {
+ // Otherwise we calculate the number of periods on the first day
+ $startDate->modify('12:00');
+ $startDate->add(new DateInterval('PT' . $periods_per_day . 'M'));
+ $result = getPeriodInterval($start_time, $startDate->getTimestamp());
+ // Add in the number of whole days worth of periods in between
+ $result += ($interval_days - 1) * $periods_per_day;
+ // And add in the number of periods on the last day
+ $result += getPeriodInterval($endDate->modify('12:00')->getTimestamp(),
$end_time);
+ }
+
+ return (int)$result;
+}
+
+
function toPeriodString($start_period, &$dur, &$units, $translate=TRUE)
{
global $periods;
Modified: mrbs/trunk/web/report.php
===================================================================
--- mrbs/trunk/web/report.php 2015-01-20 11:27:28 UTC (rev 2964)
+++ mrbs/trunk/web/report.php 2015-01-20 16:09:46 UTC (rev 2965)
@@ -873,9 +873,8 @@
// Accumulate hours/periods used, clipped to report range dates:
if ($row['enable_periods'])
{
- $dur = (min((int)$row['end_time'], $report_end) -
- max((int)$row['start_time'], $report_start)) / 60;
- $increment = ($dur % $max_periods) + floor($dur/MINUTES_PER_DAY) *
$max_periods;
+ $increment = getPeriodInterval(max($row['start_time'], $report_start),
+ min($row['end_time'], $report_end));
$room_hash[$room] = MODE_PERIODS;
}
else
------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits