From 791590dfb29c2ba069c41cf42f9048eb5c5e2e50 Mon Sep 17 00:00:00 2001 From: pratikshad Date: Mon, 27 Apr 2015 15:00:50 +0530 Subject: [PATCH] CRM-16068 Fix-Tab with table date field shows wrong date format ---------------------------------------- * CRM-16068: Tab with table date field shows wrong date format https://issues.civicrm.org/jira/browse/CRM-16068 --- CRM/Core/BAO/CustomGroup.php | 44 ++++++++----------- .../Page/MultipleRecordFieldsListing.php | 19 ++++++++ .../Page/MultipleRecordFieldsListing.tpl | 6 +-- 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 6f2772475a..df182fd789 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -1980,38 +1980,30 @@ SELECT IF( EXISTS(SELECT name FROM civicrm_contact_type WHERE name like %1), 1, switch ($dataType) { case 'Date': - $customTimeFormat = ''; $customFormat = NULL; - switch ($timeFormat) { - case 1: - $customTimeFormat = '%l:%M %P'; - break; - - case 2: - $customTimeFormat = '%H:%M'; - break; - - default: - // if time is not selected remove time from value - $value = substr($value, 0, 10); - } - - $supportableFormats = array( - 'mm/dd' => "%B %E%f $customTimeFormat", - 'dd-mm' => "%E%f %B $customTimeFormat", - 'yy' => "%Y $customTimeFormat", - 'M yy' => "%b %Y $customTimeFormat", - 'yy-mm' => "%Y-%m $customTimeFormat", - ); + $actualPHPFormats = CRM_Core_SelectValues::datePluginToPHPFormats(); if ($format = CRM_Utils_Array::value('date_format', $field)) { - if (array_key_exists($format, $supportableFormats)) { - $customFormat = $supportableFormats["$format"]; + if (array_key_exists($format, $actualPHPFormats)) { + $customTimeFormat = (array)CRM_Utils_Array::value($format, $actualPHPFormats); + switch ($timeFormat) { + case 1: + $customTimeFormat[] = 'g:iA'; + break; + + case 2: + $customTimeFormat[] = 'G:i'; + break; + + default: + // if time is not selected remove time from value + $value = substr($value, 0, 10); + } + $customFormat = implode(" ", $customTimeFormat); } } - - $retValue = CRM_Utils_Date::customFormat($value, $customFormat); + $retValue = CRM_Utils_Date::processDate($value, NULL, FALSE, $customFormat); break; case 'Boolean': diff --git a/CRM/Profile/Page/MultipleRecordFieldsListing.php b/CRM/Profile/Page/MultipleRecordFieldsListing.php index e395d00bcd..33ccc48ce8 100644 --- a/CRM/Profile/Page/MultipleRecordFieldsListing.php +++ b/CRM/Profile/Page/MultipleRecordFieldsListing.php @@ -235,6 +235,9 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities); if ($returnValues['data_type'] == 'Date') { $dateFields[$fieldIDs[$key]] = 1; + $actualPHPFormats = CRM_Core_SelectValues::datePluginToPHPFormats(); + $dateFormat = (array) CRM_Utils_Array::value($returnValues['date_format'], $actualPHPFormats); + $timeFormat = CRM_Utils_Array::value('time_format', $returnValues); } $optionValuePairs = CRM_Core_BAO_CustomOption::getCustomOption($fieldIDs[$key]); @@ -300,6 +303,22 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { if (!empty($dateFields) && array_key_exists($fieldId, $dateFields)) { // formated date capture value capture $dateFieldsVals[$fieldId][$recId] = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options); + + //set date and time format + switch ($timeFormat) { + case 1: + $dateFormat[] = 'g:iA'; + break; + + case 2: + $dateFormat[] = 'G:i'; + break; + + default: + // if time is not selected remove time from value + $result[$recId][$fieldId] = substr($result[$recId][$fieldId], 0, 10); + } + $result[$recId][$fieldId] = CRM_Utils_Date::processDate($result[$recId][$fieldId], NULL, FALSE, implode(" ", $dateFormat)); } else { // assign to $result diff --git a/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl b/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl index 9fc8504c3a..dd4aefb685 100644 --- a/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl +++ b/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl @@ -50,11 +50,7 @@ {foreach from=$records key=recId item=rows} {foreach from=$headers key=hrecId item=head} - {if $dateFieldsVals.$hrecId.$recId} - {$rows.$hrecId|crmDate:"%b %d, %Y %l:%M %P"} - {else} - {$rows.$hrecId} - {/if} + {$rows.$hrecId} {/foreach} {$rows.action} {foreach from=$dateFieldsVals key=fid item=rec} -- 2.25.1