Revision: 2702
https://sourceforge.net/p/mrbs/code/2702/
Author: cimorrison
Date: 2013-02-15 17:01:16 +0000 (Fri, 15 Feb 2013)
Log Message:
-----------
Introduced constants for SECONDS_PER_DAY etc.
Modified Paths:
--------------
mrbs/trunk/web/edit_area_room.php
mrbs/trunk/web/edit_entry.php
mrbs/trunk/web/edit_entry_handler.php
mrbs/trunk/web/functions.inc
mrbs/trunk/web/functions_table.inc
mrbs/trunk/web/internalconfig.inc.php
mrbs/trunk/web/js/edit_area_room.js.php
mrbs/trunk/web/js/edit_entry.js.php
mrbs/trunk/web/mincals.inc
mrbs/trunk/web/mrbs_sql.inc
mrbs/trunk/web/report.php
Modified: mrbs/trunk/web/edit_area_room.php
===================================================================
--- mrbs/trunk/web/edit_area_room.php 2013-02-15 14:41:24 UTC (rev 2701)
+++ mrbs/trunk/web/edit_area_room.php 2013-02-15 17:01:16 UTC (rev 2702)
@@ -432,14 +432,13 @@
// (anything less than a day is meaningless when using periods)
if ($area_enable_periods)
{
- $secs_in_day = 60*60*24;
if (isset($area_min_ba_value))
{
- $area_min_ba_value -= $area_min_ba_value%$secs_in_day;
+ $area_min_ba_value -= $area_min_ba_value % SECONDS_PER_DAY;
}
if (isset($area_max_ba_value))
{
- $area_max_ba_value -= $area_max_ba_value%$secs_in_day;
+ $area_max_ba_value -= $area_max_ba_value % SECONDS_PER_DAY;
}
}
@@ -478,7 +477,7 @@
if (hm_before(array('hours' => $area_eveningends, 'minutes' =>
$area_eveningends_minutes),
array('hours' => $area_morningstarts, 'minutes' =>
$area_morningstarts_minutes)))
{
- $start_difference += 3600;
+ $start_difference += SECONDS_PER_HOUR;
}
if ($start_difference%$area_res_mins != 0)
{
Modified: mrbs/trunk/web/edit_entry.php
===================================================================
--- mrbs/trunk/web/edit_entry.php 2013-02-15 14:41:24 UTC (rev 2701)
+++ mrbs/trunk/web/edit_entry.php 2013-02-15 17:01:16 UTC (rev 2702)
@@ -95,7 +95,7 @@
$date = getdate($t);
$t_secs = (($date['hours'] * 60) + $date['minutes']) * 60;
- $e_secs = (((($eveningends * 60) + $eveningends_minutes) * 60) +
$resolution) % (24*60*60);
+ $e_secs = (((($eveningends * 60) + $eveningends_minutes) * 60) +
$resolution) % SECONDS_PER_DAY;
if (day_past_midnight())
{
@@ -140,7 +140,7 @@
if ($area['enable_periods'])
{
- $base = 12*60*60; // The start of the first period of the day
+ $base = 12*SECONDS_PER_HOUR; // The start of the first period of the day
}
else
{
@@ -427,7 +427,7 @@
$attributes[] = 'style="display: none"';
// Put in some data about the area for use by the JavaScript
$attributes[] = 'data-enable_periods=' .
(($areas[$a]['enable_periods']) ? 1 : 0);
- $attributes[] = 'data-default_duration=' .
((isset($areas[$a]['default_duration']) && ($areas[$a]['default_duration'] !=
0)) ? $areas[$a]['default_duration'] : 60*60);
+ $attributes[] = 'data-default_duration=' .
((isset($areas[$a]['default_duration']) && ($areas[$a]['default_duration'] !=
0)) ? $areas[$a]['default_duration'] : SECONDS_PER_HOUR);
$attributes[] = 'data-max_duration_enabled=' .
(($areas[$a]['max_duration_enabled']) ? 1 : 0);
$attributes[] = 'data-max_duration_secs=' .
$areas[$a]['max_duration_secs'];
$attributes[] = 'data-max_duration_periods=' .
$areas[$a]['max_duration_periods'];
@@ -938,7 +938,7 @@
{
if (!isset($default_duration))
{
- $default_duration = (60 * 60);
+ $default_duration = SECONDS_PER_HOUR;
}
$duration = ($enable_periods ? 60 : $default_duration);
$end_time = $start_time + $duration;
@@ -1053,7 +1053,7 @@
// Get the start and end of the booking day
if ($row['enable_periods'])
{
- $first = 12*60*60;
+ $first = 12*SECONDS_PER_HOUR;
// If we're using periods we just go to the end of the last slot
$last = $first + (count($periods) * $row['resolution']);
}
@@ -1064,7 +1064,7 @@
// If the end of the day is the same as or before the start time, then
it's really on the next day
if ($first >= $last)
{
- $last += 24*60*60;
+ $last += SECONDS_PER_DAY;
}
}
$row['first'] = $first;
Modified: mrbs/trunk/web/edit_entry_handler.php
===================================================================
--- mrbs/trunk/web/edit_entry_handler.php 2013-02-15 14:41:24 UTC (rev
2701)
+++ mrbs/trunk/web/edit_entry_handler.php 2013-02-15 17:01:16 UTC (rev
2702)
@@ -321,7 +321,7 @@
{
if ($enable_periods)
{
- $start_seconds = 12 * 60 * 60;
+ $start_seconds = 12 * SECONDS_PER_HOUR;
// This is actually the start of the last period, which is what the form
would
// have returned. It will get corrected in a moment.
$end_seconds = $start_seconds + ((count($periods) - 1) * 60);
@@ -339,10 +339,10 @@
// $returl will end up taking us back to the day we started on
if (day_past_midnight())
{
- $end_last = (((($eveningends * 60) + $eveningends_minutes) *60) +
$resolution) % (24*60*60);
+ $end_last = (((($eveningends * 60) + $eveningends_minutes) *60) +
$resolution) % SECONDS_PER_DAY;
if ($start_seconds < $end_last)
{
- $start_seconds += 24*60*60;
+ $start_seconds += SECONDS_PER_DAY;
$day_before = getdate(mktime(0, 0, 0, $start_month, $start_day-1,
$start_year));
$start_day = $day_before['mday'];
$start_month = $day_before['mon'];
@@ -421,7 +421,9 @@
isset($rep_end_month) && isset($rep_end_day) && isset($rep_end_year))
{
// Get the repeat entry settings
- $end_date = mktime(intval($start_seconds/3600),
intval(($start_seconds%3600)/60), 0,
+ $end_date = mktime(intval($start_seconds/SECONDS_PER_HOUR),
+ intval(($start_seconds%SECONDS_PER_HOUR)/60),
+ 0,
$rep_end_month, $rep_end_day, $rep_end_year);
}
else
Modified: mrbs/trunk/web/functions.inc
===================================================================
--- mrbs/trunk/web/functions.inc 2013-02-15 14:41:24 UTC (rev 2701)
+++ mrbs/trunk/web/functions.inc 2013-02-15 17:01:16 UTC (rev 2702)
@@ -296,14 +296,13 @@
$max_periods = count($periods);
$dur /= 60; // duration now in minutes
- $mins_in_day = 24*60;
- $days = $dur / $mins_in_day;
- $remainder = $dur % $mins_in_day;
+ $days = $dur / MINUTES_PER_DAY;
+ $remainder = $dur % MINUTES_PER_DAY;
// strip out any gap between the end of the last period on one day
// and the beginning of the first on the next
if ($remainder > $max_periods)
{
- $remainder += $max_periods - $mins_in_day;
+ $remainder += $max_periods - MINUTES_PER_DAY;
}
// We'll express the duration as an integer, in days if possible, otherwise
periods
@@ -342,18 +341,18 @@
$end_period = $start_period + $units;
if ($end_period > $max_periods)
{
- $units = (24*60*floor($end_period/$max_periods)) +
($end_period%$max_periods) - $start_period;
+ $units = (MINUTES_PER_DAY * floor($end_period/$max_periods)) +
($end_period%$max_periods) - $start_period;
}
}
if ($dur_units == "days")
{
if ($start_period == 0)
{
- $units = $max_periods + ($units-1)*60*24;
+ $units = $max_periods + ($units-1)*MINUTES_PER_DAY;
}
else
{
- $units = $units * 60 * 24;
+ $units = $units * MINUTES_PER_DAY;
}
}
@@ -461,7 +460,7 @@
$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);
+ $end_last_slot = $end_last_slot % SECONDS_PER_DAY;
return ($end_last_slot <= $start_first_slot);
}
@@ -1774,9 +1773,8 @@
// seconds since the start of the day, $s
function hour_min($s)
{
- $seconds_per_day = 24*60*60;
- $following_day = ($s >= $seconds_per_day);
- $s = $s % $seconds_per_day; // in case $s is on the next day
+ $following_day = ($s >= SECONDS_PER_DAY);
+ $s = $s % SECONDS_PER_DAY; // in case $s is on the next day
// Choose a day that doesn't have any DST transitions in any timezone
$t = mktime(0, 0, $s, 1, 1, 2000);
$result = utf8_strftime(hour_min_format(), $t);
@@ -2296,7 +2294,7 @@
{
if (date('I', $t))
{
- $change = cross_dst($t, $t+(24*60*60));
+ $change = cross_dst($t, $t+SECONDS_PER_DAY);
return !date('I', $t + $change);
}
return false;
@@ -2340,12 +2338,12 @@
// entering DST
if (!date( "I", $start) && date( "I", $end))
{
- $modification = -3600;
+ $modification = -SECONDS_PER_HOUR;
}
// leaving DST
else if (date( "I", $start) && !date( "I", $end))
{
- $modification = 3600;
+ $modification = SECONDS_PER_HOUR;
}
else
{
@@ -2427,7 +2425,7 @@
// First let's calculate (a)
$last = mktime(12, 0, 0, date('n', $last), date('j', $last), date('Y',
$last));
$first = mktime(12, 0, 0, date('n', $first), date('j', $first), date('Y',
$first));
- $days_diff = (int) round(($last - $first)/(60*60*24)); // the difference in
days
+ $days_diff = (int) round(($last - $first)/SECONDS_PER_DAY); // the
difference in days
$whole_weeks = (int) floor($days_diff/7); // the number of whole weeks
between the two
$non_working_days = $whole_weeks * (7 - $n_working_days);
// Now (b), ie we just have to calculate how many non-working days there are
between the two
@@ -2445,7 +2443,7 @@
}
// So now subtract the number of weekend seconds
- $diff = $diff - ($non_working_days * 60*60*24);
+ $diff = $diff - ($non_working_days * SECONDS_PER_DAY);
// Finally reverse the difference if $now was in fact before $then
if ($now < $then)
Modified: mrbs/trunk/web/functions_table.inc
===================================================================
--- mrbs/trunk/web/functions_table.inc 2013-02-15 14:41:24 UTC (rev 2701)
+++ mrbs/trunk/web/functions_table.inc 2013-02-15 17:01:16 UTC (rev 2702)
@@ -643,13 +643,12 @@
global $morningstarts, $morningstarts_minutes, $eveningends,
$eveningends_minutes;
global $resolution;
- $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;
+ $end_last = $end_last % SECONDS_PER_DAY;
if (day_past_midnight())
{
- $end_last += $seconds_per_day;
+ $end_last += SECONDS_PER_DAY;
}
$n_slots = ($end_last - $start_first)/$resolution;
Modified: mrbs/trunk/web/internalconfig.inc.php
===================================================================
--- mrbs/trunk/web/internalconfig.inc.php 2013-02-15 14:41:24 UTC (rev
2701)
+++ mrbs/trunk/web/internalconfig.inc.php 2013-02-15 17:01:16 UTC (rev
2702)
@@ -91,6 +91,13 @@
// in calls to nl2br. TRUE means XHTML, FALSE means HTML.
define('IS_XHTML', FALSE);
+
+/*************************************************
+ * General constants - internal use, do not change
+ *************************************************/
+ define('MINUTES_PER_DAY', 24*60);
+ define('SECONDS_PER_DAY', MINUTES_PER_DAY * 60);
+ define('SECONDS_PER_HOUR', 3600);
/*************************************************
* REPORT constants - internal use, do not change
Modified: mrbs/trunk/web/js/edit_area_room.js.php
===================================================================
--- mrbs/trunk/web/js/edit_area_room.js.php 2013-02-15 14:41:24 UTC (rev
2701)
+++ mrbs/trunk/web/js/edit_area_room.js.php 2013-02-15 17:01:16 UTC (rev
2702)
@@ -110,7 +110,7 @@
firstSlot, lastSlot,
morningStarts, eveningEnds,
eveningEndsInput,
- minsPerDay = 24*60;
+ minsPerDay = <?php echo MINUTES_PER_DAY ?>;
resMins = parseInt($('#area_res_mins').val(), 10);
if (resMins === 0)
Modified: mrbs/trunk/web/js/edit_entry.js.php
===================================================================
--- mrbs/trunk/web/js/edit_entry.js.php 2013-02-15 14:41:24 UTC (rev 2701)
+++ mrbs/trunk/web/js/edit_entry.js.php 2013-02-15 17:01:16 UTC (rev 2702)
@@ -698,21 +698,21 @@
var currentArea = $('#area').data('current');
var enablePeriods = areaConfig('enable_periods');
var durDays;
+ var minutesPerDay = <?php echo MINUTES_PER_DAY ?>;
durUnits = (enablePeriods) ? '<?php echo "periods" ?>' : '<?php echo
"minutes" ?>';
duration = to - from;
duration = Math.floor((to - from) / 60);
<?php
- // Adjust the days and duration so that 0 <= duration < 24*60. If we're
using
- // periods then if necessary add/subtract multiples of the number of periods
in
- // a day
+ // Adjust the days and duration so that 0 <= duration < minutesPerDay. If
we're using
+ // periods then if necessary add/subtract multiples of the number of periods
in a day
?>
- durDays = Math.floor(duration/(24*60));
+ durDays = Math.floor(duration/minutesPerDay);
if (durDays !== 0)
{
days += durDays;
- duration -= durDays * ((enablePeriods) ? $('#rooms' +
currentArea).find('option').length : 24*60);
+ duration -= durDays * ((enablePeriods) ? $('#rooms' +
currentArea).find('option').length : minutesPerDay);
}
if (enablePeriods)
@@ -757,7 +757,8 @@
?>
function getDateDifference()
{
- var diff;
+ var diff,
+ secondsPerDay = <?php echo SECONDS_PER_DAY ?>;
<?php
if (!$is_admin && $auth['only_admin_can_book_multiday'])
@@ -781,7 +782,7 @@
parseInt(end[2], 10),
12);
- diff = (endDate - startDate)/(24 * 60 * 60 * 1000);
+ diff = (endDate - startDate)/(secondsPerDay * 1000);
diff = Math.round(diff);
<?php
}
@@ -1031,6 +1032,7 @@
maxDurationPeriods = areaConfig('max_duration_periods'),
maxDurationQty = areaConfig('max_duration_qty'),
maxDurationUnits = areaConfig('max_duration_units'),
+ secondsPerDay = <?php echo SECONDS_PER_DAY ?>,
duration,
maxDuration;
@@ -1053,7 +1055,7 @@
}
else
{
- duration += dateDifference * 60 * 60 *24;
+ duration += dateDifference * secondsPerDay;
}
maxDuration = (enablePeriods) ? maxDurationPeriods : maxDurationSecs;
if (duration > maxDuration)
Modified: mrbs/trunk/web/mincals.inc
===================================================================
--- mrbs/trunk/web/mincals.inc 2013-02-15 14:41:24 UTC (rev 2701)
+++ mrbs/trunk/web/mincals.inc 2013-02-15 17:01:16 UTC (rev 2702)
@@ -102,7 +102,7 @@
$basetime = mktime(12,0,0,6,11+$weekstarts,2000);
for ($i = 0, $s = ""; $i < 7; $i++)
{
- $show = $basetime + ($i * 24 * 60 * 60);
+ $show = $basetime + ($i * SECONDS_PER_DAY);
$fl = utf8_strftime($strftime_format['dayname_cal'], $show);
// add a class if it's a hidden day so that we can apply special styling
if (is_hidden_day(($i + $weekstarts) % 7))
@@ -141,7 +141,7 @@
// problems when we come to look at the difference ($diff) further down
if the two ends of the
// time period straddle a DST boundary.
$sticky_time = gmmktime(12, 0, 0, $month, $day, $year); // Use
gm to avoid DST problems
- $start_highlight_gmtime = $sticky_time - ($skipback * 24 * 60 * 60);
+ $start_highlight_gmtime = $sticky_time - ($skipback * SECONDS_PER_DAY);
}
$daysInMonth = $this->getDaysInMonth($this->month, $this->year);
Modified: mrbs/trunk/web/mrbs_sql.inc
===================================================================
--- mrbs/trunk/web/mrbs_sql.inc 2013-02-15 14:41:24 UTC (rev 2701)
+++ mrbs/trunk/web/mrbs_sql.inc 2013-02-15 17:01:16 UTC (rev 2702)
@@ -252,7 +252,6 @@
global $interval_types, $strftime_format;
$errors = array();
- $secs_in_day = 60*60*24;
// The booking policies don't apply to booking admins for this room
$user = getUserName();
@@ -271,7 +270,7 @@
{
if ($enable_periods)
{
- $min_book_ahead_secs -= $min_book_ahead_secs%$secs_in_day;
+ $min_book_ahead_secs -= $min_book_ahead_secs % SECONDS_PER_DAY;
}
$min_book_ahead = $min_book_ahead_secs;
if (($booking['start_time'] - $now) < $min_book_ahead)
@@ -291,7 +290,7 @@
{
if ($enable_periods)
{
- $max_book_ahead_secs -= $max_book_ahead_secs%$secs_in_day;
+ $max_book_ahead_secs -= $max_book_ahead_secs % SECONDS_PER_DAY;
}
$max_book_ahead = $max_book_ahead_secs;
if (($booking['end_time'] - $now) > $max_book_ahead)
Modified: mrbs/trunk/web/report.php
===================================================================
--- mrbs/trunk/web/report.php 2013-02-15 14:41:24 UTC (rev 2701)
+++ mrbs/trunk/web/report.php 2013-02-15 17:01:16 UTC (rev 2702)
@@ -829,7 +829,7 @@
$array[$index1][$index2] += $increment;
}
-// Collect summary statistics on one entry. See below for columns in $row[].
+// Collect summary statistics on one entry.
// This also builds hash tables of all unique names and rooms. When sorted,
// these will become the column and row headers of the summary table.
function accumulate(&$row, &$count, &$hours, $report_start, $report_end,
@@ -853,13 +853,13 @@
{
$dur = (min((int)$row['end_time'], $report_end) -
max((int)$row['start_time'], $report_start)) / 60;
- $increment = ($dur % $max_periods) + floor( $dur/(24*60) ) * $max_periods;
+ $increment = ($dur % $max_periods) + floor($dur/MINUTES_PER_DAY) *
$max_periods;
$room_hash[$room] = MODE_PERIODS;
}
else
{
$increment = (min((int)$row['end_time'], $report_end) -
- max((int)$row['start_time'], $report_start)) / 3600.0;
+ max((int)$row['start_time'], $report_start)) /
SECONDS_PER_HOUR;
$room_hash[$room] = MODE_TIMES;
}
increment_count($hours, $room, $name, $increment);
------------------------------------------------------------------------------
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