summaryrefslogtreecommitdiff
path: root/adodb-time.inc.php
diff options
context:
space:
mode:
authorMark Newnham <mark@newnhams.com>2016-04-13 17:19:26 -0600
committerDamien Regad <dregad@mantisbt.org>2016-04-27 19:11:57 +0200
commit54dce6ab773d87aa62c931f7b52a7f94eac6f4ad (patch)
tree54d63e5cf4575456da00d5ae7dab13a8ed20cf98 /adodb-time.inc.php
parent97372fc2ff5062ef805e65256706169e0d2cb751 (diff)
downloadadodb-54dce6ab773d87aa62c931f7b52a7f94eac6f4ad.tar.gz
adodb-54dce6ab773d87aa62c931f7b52a7f94eac6f4ad.tar.bz2
adodb-54dce6ab773d87aa62c931f7b52a7f94eac6f4ad.zip
Quarter of year not returned correctly
The ADOdb date/time library includes support for the time format 'Q' which returns the quarter of the year that the provided date falls into. This format is not supported by the standard PHP library, which means that if the provided date falls into the 32-bit date range where ADOdb hands off data calculations to the standard gmdate() for performance reasons, then the value is not calculated. The solution would be that, if a supplied format contained the 'Q' character, it would bypass the normal 32 bit test and be handled by the adodb date library in adodb_date() In addition, the quarter function does not return the correct value, it returns 3rds of a year instead of Quarters. Fixes #222
Diffstat (limited to 'adodb-time.inc.php')
-rw-r--r--adodb-time.inc.php15
1 files changed, 12 insertions, 3 deletions
diff --git a/adodb-time.inc.php b/adodb-time.inc.php
index 9fa40a6f..e5caa2b3 100644
--- a/adodb-time.inc.php
+++ b/adodb-time.inc.php
@@ -1071,7 +1071,6 @@ static $daylight;
global $ADODB_DATETIME_CLASS;
static $jan1_1971;
-
if (!isset($daylight)) {
$daylight = function_exists('adodb_daylight_sv');
if (empty($jan1_1971)) $jan1_1971 = mktime(0,0,0,1,1,1971); // we only use date() when > 1970 as adodb_mktime() only uses mktime() when > 1970
@@ -1079,7 +1078,15 @@ static $jan1_1971;
if ($d === false) return ($is_gmt)? @gmdate($fmt): @date($fmt);
if (!defined('ADODB_TEST_DATES')) {
- if ((abs($d) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range
+
+ /*
+ * Format 'Q' is an ADOdb custom format, not supported in PHP
+ * so if there is a 'Q' in the format, we force it to use our
+ * function. There is a trivial overhead in this
+ */
+
+ if ((abs($d) <= 0x7FFFFFFF) && strpos($fmt,'Q') === false)
+ { // check if number in 32-bit signed range
if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= $jan1_1971) // if windows, must be +ve integer
return ($is_gmt)? @gmdate($fmt,$d): @date($fmt,$d);
@@ -1145,7 +1152,9 @@ static $jan1_1971;
case 'y': $dates .= substr($year,strlen($year)-2,2); break;
// MONTH
case 'm': if ($month<10) $dates .= '0'.$month; else $dates .= $month; break;
- case 'Q': $dates .= ($month+3)>>2; break;
+ case 'Q':
+ $dates .= ceil($month / 3);
+ break;
case 'n': $dates .= $month; break;
case 'M': $dates .= date('M',mktime(0,0,0,$month,2,1971)); break;
case 'F': $dates .= date('F',mktime(0,0,0,$month,2,1971)); break;