Revision: 2973
https://sourceforge.net/p/mrbs/code/2973/
Author: cimorrison
Date: 2015-01-21 19:11:36 +0000 (Wed, 21 Jan 2015)
Log Message:
-----------
Put in a workaround for the DateTime::modify() bug and moved the minimum PHP
version back to 5.3.0. See SF Support Requests #667.
Modified Paths:
--------------
mrbs/trunk/INSTALL
mrbs/trunk/web/defaultincludes.inc
mrbs/trunk/web/functions.inc
mrbs/trunk/web/internalconfig.inc.php
mrbs/trunk/web/report.php
Added Paths:
-----------
mrbs/trunk/web/lib/
mrbs/trunk/web/lib/MRBS/
mrbs/trunk/web/lib/MRBS/DateTime.php
mrbs/trunk/web/lib/autoload.inc
Modified: mrbs/trunk/INSTALL
===================================================================
--- mrbs/trunk/INSTALL 2015-01-21 14:18:47 UTC (rev 2972)
+++ mrbs/trunk/INSTALL 2015-01-21 19:11:36 UTC (rev 2973)
@@ -12,7 +12,7 @@
maintain, and back up your chosen database system.
No optional PHP packages (other than the database system) are required for
-this application. PHP Version 5.3.6 or later is required.
+this application. PHP Version 5.3.0 or later is required.
You can run PHP either as a CGI or with a direct module interface (also called
SAPI). These servers include Apache, Microsoft Internet Information Server,
Modified: mrbs/trunk/web/defaultincludes.inc
===================================================================
--- mrbs/trunk/web/defaultincludes.inc 2015-01-21 14:18:47 UTC (rev 2972)
+++ mrbs/trunk/web/defaultincludes.inc 2015-01-21 19:11:36 UTC (rev 2973)
@@ -6,6 +6,7 @@
// are assigned to variables will change depending on the context in which the
file
// is called.
+require_once "lib/autoload.inc";
require "grab_globals.inc.php";
require_once "systemdefaults.inc.php";
require_once "areadefaults.inc.php";
Modified: mrbs/trunk/web/functions.inc
===================================================================
--- mrbs/trunk/web/functions.inc 2015-01-21 14:18:47 UTC (rev 2972)
+++ mrbs/trunk/web/functions.inc 2015-01-21 19:11:36 UTC (rev 2973)
@@ -313,15 +313,17 @@
$periods_per_day = count($periods);
- $startDate = new DateTime();
+ // Need to use the MRBS version of DateTime to get round a bug in modify()
+ // in PHP before 5.3.6
+ $startDate = new MRBS\DateTime();
$startDate->setTimestamp($start_time);
- $endDate = new DateTime();
+ $endDate = new MRBS\DateTime();
$endDate->setTimestamp($end_time);
// Set both dates to noon so that we can compare them and get an integral
// number of days difference. Noon also happens to be when periods start,
// so will be useful in a moment.
- $startDate->modify('12:00'); // This won't work in PHP < 5.3.6 (bug)
+ $startDate->modify('12:00');
$endDate->modify('12:00');
// Calculate the difference in days
Modified: mrbs/trunk/web/internalconfig.inc.php
===================================================================
--- mrbs/trunk/web/internalconfig.inc.php 2015-01-21 14:18:47 UTC (rev
2972)
+++ mrbs/trunk/web/internalconfig.inc.php 2015-01-21 19:11:36 UTC (rev
2973)
@@ -113,8 +113,7 @@
********************************************************/
// Check PHP version
-// We need 5.3.6 because it fixes a bug that causes DateTime::modify('noon')
not to work
-$min_PHP_version = '5.3.6';
+$min_PHP_version = '5.3.0';
if (!function_exists('version_compare') || version_compare(PHP_VERSION,
$min_PHP_version) < 0)
{
die("MRBS requires PHP $min_PHP_version or above. This server is running
version " . PHP_VERSION . ".");
Added: mrbs/trunk/web/lib/MRBS/DateTime.php
===================================================================
--- mrbs/trunk/web/lib/MRBS/DateTime.php (rev 0)
+++ mrbs/trunk/web/lib/MRBS/DateTime.php 2015-01-21 19:11:36 UTC (rev
2973)
@@ -0,0 +1,75 @@
+<?php
+namespace MRBS;
+
+class DateTime extends \DateTime
+{
+ // Workaround for a bug that was fixed in PHP 5.3.6
+ // Only supports a limited range of $modify strings for PHP < 5.3.6. Throws
+ // an exception if passed a string that it can't handle (maybe it should just
+ // generate a warning? - that's what the global DateTime does)
+ public function modify($modify)
+ {
+ if (version_compare(PHP_VERSION, '5.3.6') >= 0)
+ {
+ return parent::modify($modify);
+ }
+
+ $date = getdate($this->getTimestamp());
+ $modification = self::parse($modify);
+
+ foreach ($modification as $unit => $amount)
+ {
+ switch($amount['mode'])
+ {
+ case 'absolute':
+ $date[$unit] = $amount['quantity'];
+ break;
+ case 'relative':
+ $date[$unit] = $date[$unit] + $amount['quantity'];
+ break;
+ default:
+ throw new Exception ("Unknown mode '" . $amount['mode'] . "'");
+ break;
+ }
+ }
+
+ $modified_timestamp = mktime($date['hours'], $date['minutes'],
$date['seconds'],
+ $date['mon'], $date['mday'], $date['year']);
+
+ return $this->setTimestamp($modified_timestamp);
+ }
+
+
+ // Parse the $modify string and return an array of any modifications that
are necessary.
+ // The array is indexed at the top level by 'hours', 'minutes', 'seconds',
'mon', 'mday' and
+ // 'year' - ie the same keys that the output of getdate() uses. Each value
is itself an array,
+ // indexed by 'mode' (can be 'relative' or 'absolute') and then 'quantity'.
If the mode is
+ // relative then the quantity is added to the original, if absolute then it
replaces the original.
+ private static function parse($modify)
+ {
+ $modify = self::map($modify);
+
+ // Test for a simple hh:mm pattern (or hhmm or hh.mm)
+ $pattern = '/([01][0-9]|[2][0-3])[.:]?([0-5][0-9])/';
+ if (preg_match($pattern, $modify, $matches))
+ {
+ return array('hours' => array('mode' => 'absolute',
+ 'quantity' => $matches[1]),
+ 'minutes' => array('mode' => 'absolute',
+ 'quantity' => $matches[2]));
+ }
+
+ // Could add more tests later if need be.
+ throw new Exception("Modify string '$modify' not supported by MRBS");
+ }
+
+
+ // Replace some simple modify strings with their numeric alternatives.
+ private static function map($modify)
+ {
+ $mappings = array('midnight' => '00:00',
+ 'noon' => '12:00');
+
+ return (isset($mappings[$modify])) ? $mappings[$modify] : $modify;
+ }
+}
Property changes on: mrbs/trunk/web/lib/MRBS/DateTime.php
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: mrbs/trunk/web/lib/autoload.inc
===================================================================
--- mrbs/trunk/web/lib/autoload.inc (rev 0)
+++ mrbs/trunk/web/lib/autoload.inc 2015-01-21 19:11:36 UTC (rev 2973)
@@ -0,0 +1,17 @@
+<?php
+
+// $Id$
+
+spl_autoload_register(function ($class) {
+
+ $base_dir = __DIR__ . '/';
+
+ // Replace namespace separators with directory separators.
+ // Append '.php'
+ $file = $base_dir . str_replace('\\', '/', $class) . '.php';
+
+ if (file_exists($file))
+ {
+ require $file;
+ }
+});
\ No newline at end of file
Property changes on: mrbs/trunk/web/lib/autoload.inc
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: mrbs/trunk/web/report.php
===================================================================
--- mrbs/trunk/web/report.php 2015-01-21 14:18:47 UTC (rev 2972)
+++ mrbs/trunk/web/report.php 2015-01-21 19:11:36 UTC (rev 2973)
@@ -877,10 +877,13 @@
// on those days. Otherwise if the report starts or ends in the middle
of a multi-day
// booking we'll get all those spurious minutes before noon or between the
end of
// the last period and midnight
- $startDate = new DateTime();
+
+ // Need to use the MRBS version of DateTime to get round a bug in modify()
+ // in PHP before 5.3.6
+ $startDate = new MRBS\DateTime();
$startDate->setTimestamp($report_start)->modify('12:00');
- $endDate = new DateTime();
+ $endDate = new MRBS\DateTime();
$endDate->setTimestamp($report_end)->modify('12:00');
$endDate->sub(new DateInterval('P1D')); // Go back one day because the
$report_end is at 00:00 the day after
$endDate->add(new DateInterval('PT' . $periods_per_day . 'M'));
------------------------------------------------------------------------------
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