Skip to content

Commit

Permalink
Merge pull request #10497 from JMAConsulting/CRM-20721
Browse files Browse the repository at this point in the history
CRM-20721: Add parameter to dateQueryBuilder fn to change date value to desired format
  • Loading branch information
colemanw authored Jun 26, 2017
2 parents 895ef8f + d51e281 commit 8505c69
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -5219,11 +5219,13 @@ public static function &defaultHierReturnProperties() {
* @param string $dbFieldName
* @param string $fieldTitle
* @param bool $appendTimeStamp
* @param string $dateFormat
*/
public function dateQueryBuilder(
&$values, $tableName, $fieldName,
$dbFieldName, $fieldTitle,
$appendTimeStamp = TRUE
$appendTimeStamp = TRUE,
$dateFormat = 'YmdHis'
) {
list($name, $op, $value, $grouping, $wildcard) = $values;

Expand All @@ -5240,7 +5242,7 @@ public function dateQueryBuilder(
if ($name == $fieldName . '_low') {
$firstOP = '>=';
$firstPhrase = ts('greater than or equal to');
$firstDate = CRM_Utils_Date::processDate($value);
$firstDate = CRM_Utils_Date::processDate($value, NULL, FALSE, $dateFormat);

$secondValues = $this->getWhereValues("{$fieldName}_high", $grouping);
if (!empty($secondValues) && $secondValues[2]) {
Expand All @@ -5251,7 +5253,7 @@ public function dateQueryBuilder(
if ($appendTimeStamp && strlen($secondValue) == 10) {
$secondValue .= ' 23:59:59';
}
$secondDate = CRM_Utils_Date::processDate($secondValue);
$secondDate = CRM_Utils_Date::processDate($secondValue, NULL, FALSE, $dateFormat);
}
}
elseif ($name == $fieldName . '_high') {
Expand All @@ -5261,14 +5263,14 @@ public function dateQueryBuilder(
if ($appendTimeStamp && strlen($value) == 10) {
$value .= ' 23:59:59';
}
$firstDate = CRM_Utils_Date::processDate($value);
$firstDate = CRM_Utils_Date::processDate($value, NULL, FALSE, $dateFormat);

$secondValues = $this->getWhereValues("{$fieldName}_low", $grouping);
if (!empty($secondValues) && $secondValues[2]) {
$secondOP = '>=';
$secondPhrase = ts('greater than or equal to');
$secondValue = $secondValues[2];
$secondDate = CRM_Utils_Date::processDate($secondValue);
$secondDate = CRM_Utils_Date::processDate($secondValue, NULL, FALSE, $dateFormat);
}
}

Expand Down Expand Up @@ -5309,7 +5311,7 @@ public function dateQueryBuilder(
if (strstr($op, 'IN')) {
$format = array();
foreach ($value as &$date) {
$date = CRM_Utils_Date::processDate($date);
$date = CRM_Utils_Date::processDate($date, NULL, FALSE, $dateFormat);
if (!$appendTimeStamp) {
$date = substr($date, 0, 8);
}
Expand All @@ -5319,7 +5321,7 @@ public function dateQueryBuilder(
$format = implode(', ', $format);
}
elseif ($value && (!strstr($op, 'NULL') && !strstr($op, 'EMPTY'))) {
$date = CRM_Utils_Date::processDate($value);
$date = CRM_Utils_Date::processDate($value, NULL, FALSE, $dateFormat);
if (!$appendTimeStamp) {
$date = substr($date, 0, 8);
}
Expand Down

0 comments on commit 8505c69

Please sign in to comment.