From 6004d2f7b83a5594173a80d3b21fc8d15576340c Mon Sep 17 00:00:00 2001 From: Sunil Pawar Date: Tue, 12 Jan 2021 17:34:51 +0530 Subject: [PATCH] Additional improvement as discussion in PR review --- CRM/Contact/BAO/Contact.php | 6 +----- CRM/Utils/Date.php | 5 +---- templates/CRM/Contact/Page/Inline/Demographics.tpl | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index e90708118d..9df85abcbb 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -2599,11 +2599,7 @@ LEFT JOIN civicrm_email ON ( civicrm_contact.id = civicrm_email.contact_id ) if ($contact->birth_date) { $birthDate = CRM_Utils_Date::customFormat($contact->birth_date, '%Y%m%d'); if ($birthDate < date('Ymd')) { - $deceasedDate = NULL; - if (!empty($contact->is_deceased) && !empty($contact->deceased_date)) { - $deceasedDate = $contact->deceased_date; - } - $age = CRM_Utils_Date::calculateAge($birthDate, $deceasedDate); + $age = CRM_Utils_Date::calculateAge($birthDate, $contact->deceased_date ?? NULL); $values['age']['y'] = $age['years'] ?? NULL; $values['age']['m'] = $age['months'] ?? NULL; } diff --git a/CRM/Utils/Date.php b/CRM/Utils/Date.php index f92c8cfc2a..d33105c7c5 100644 --- a/CRM/Utils/Date.php +++ b/CRM/Utils/Date.php @@ -907,10 +907,7 @@ class CRM_Utils_Date { $birthYear = $bDate[0]; $birthMonth = $bDate[1]; $birthDay = $bDate[2]; - if (empty($targetDate)) { - $targetDate = date('Y-m-d'); - } - $targetDate = strtotime($targetDate); + $targetDate = strtotime($targetDate ?? date('Y-m-d')); $year_diff = date("Y", $targetDate) - $birthYear; diff --git a/templates/CRM/Contact/Page/Inline/Demographics.tpl b/templates/CRM/Contact/Page/Inline/Demographics.tpl index 72247a2fb4..4f7d4f1f45 100644 --- a/templates/CRM/Contact/Page/Inline/Demographics.tpl +++ b/templates/CRM/Contact/Page/Inline/Demographics.tpl @@ -34,7 +34,7 @@
{assign var="date_format" value = $fields.birth_date.smarty_view_format} {$deceased_date|crmDate:$date_format} - ({if $age.y}{ts count=$age.y plural='%count years'}%count year{/ts}{elseif $age.m}{ts count=$age.m plural='%count months'}%count month{/ts}{/if}) + ({ts}Age{/ts} {if $age.y}{ts count=$age.y plural='%count years'}%count year{/ts}{elseif $age.m}{ts count=$age.m plural='%count months'}%count month{/ts}{/if})
{else} -- 2.25.1