CRM-16068 Fix-Tab with table date field shows wrong date format
authorpratikshad <pratiksha.dubey@webaccess.co.in>
Mon, 27 Apr 2015 09:30:50 +0000 (15:00 +0530)
committerpratikshad <pratiksha.dubey@webaccess.co.in>
Tue, 28 Apr 2015 07:24:54 +0000 (12:54 +0530)
----------------------------------------
* CRM-16068: Tab with table date field shows wrong date format
  https://issues.civicrm.org/jira/browse/CRM-16068

CRM/Core/BAO/CustomGroup.php
CRM/Profile/Page/MultipleRecordFieldsListing.php
templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl

index 6f2772475abe28b7c1c0535644040489bf23c4da..df182fd789a163c2b54b6c931a2b9115b4569db2 100644 (file)
@@ -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':
index e395d00bcd1c73d71c24e8199cf78d6f0bb0c138..33ccc48ce8bc9645aa768c52375c46e31ba88217 100644 (file)
@@ -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
index 9fc8504c3a70d4a4202f36671a66b3ad86455ac8..dd4aefb68591a89c1a0b2945296674a0a9b9bea4 100644 (file)
             {foreach from=$records key=recId item=rows}
               <tr class="{cycle values="odd-row,even-row"}">
                 {foreach from=$headers key=hrecId item=head}
-                  {if $dateFieldsVals.$hrecId.$recId}
-                    <td {crmAttributes a=$attributes.$hrecId.$recId}>{$rows.$hrecId|crmDate:"%b %d, %Y %l:%M %P"}</td>
-                  {else}
-                    <td {crmAttributes a=$attributes.$hrecId.$recId}>{$rows.$hrecId}</td>
-                  {/if}
+                  <td {crmAttributes a=$attributes.$hrecId.$recId}>{$rows.$hrecId}</td>
                 {/foreach}
                 <td>{$rows.action}</td>
                 {foreach from=$dateFieldsVals key=fid item=rec}