From fc6f60f48a72ce4f0531809a49ff41ad4b9608ad Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 15 Jun 2022 13:20:20 +1000 Subject: [PATCH] [REF] Replace usage of smarty's date_filter to ensure we don't call strftime which is deprecated in php8.1 Ensure start date format is the same --- CRM/Core/Smarty/plugins/modifier.crmDate.php | 4 +++- CRM/Utils/Date.php | 3 ++- templates/CRM/Activity/Calendar/ICal.tpl | 2 +- templates/CRM/Contribute/Form/Contribution/Main.tpl | 2 +- .../CRM/Contribute/Form/Contribution/MembershipBlock.tpl | 4 ++-- templates/CRM/Core/Calendar/ICal.tpl | 2 +- templates/CRM/Core/Calendar/Rss.tpl | 4 ++-- templates/CRM/Event/Form/Registration/EventInfoBlock.tpl | 2 +- templates/CRM/Event/Form/Selector.tpl | 2 +- templates/CRM/Event/Form/Task/Print.tpl | 2 +- templates/CRM/Event/Page/EventInfo.tpl | 2 +- templates/CRM/Event/Page/List.tpl | 2 +- templates/CRM/Event/Page/UserDashboard.tpl | 2 +- templates/CRM/common/l10n.js.tpl | 2 +- templates/CRM/common/navigation.js.tpl | 2 +- 15 files changed, 20 insertions(+), 17 deletions(-) diff --git a/CRM/Core/Smarty/plugins/modifier.crmDate.php b/CRM/Core/Smarty/plugins/modifier.crmDate.php index 2a175bcfc0..b81855ae94 100644 --- a/CRM/Core/Smarty/plugins/modifier.crmDate.php +++ b/CRM/Core/Smarty/plugins/modifier.crmDate.php @@ -60,7 +60,9 @@ function smarty_modifier_crmDate($dateString, ?string $dateFormat = NULL, bool $ $config = CRM_Core_Config::singleton(); $dateFormat = $config->dateformatTime; } - + if (is_int($dateString)) { + return CRM_Utils_Date::customFormatTs($dateString, $dateFormat); + } return CRM_Utils_Date::customFormat($dateString, $dateFormat); } return ''; diff --git a/CRM/Utils/Date.php b/CRM/Utils/Date.php index 1bdabb2b60..a08e6b7d68 100644 --- a/CRM/Utils/Date.php +++ b/CRM/Utils/Date.php @@ -369,7 +369,7 @@ class CRM_Utils_Date { $hour24 = (int) substr($dateString, 11, 2); $minute = (int) substr($dateString, 14, 2); - $second = (int) substr($dateString, 16, 2); + $second = (int) substr($dateString, 17, 2); } else { $year = (int) substr($dateString, 0, 4); @@ -433,6 +433,7 @@ class CRM_Utils_Date { '%A' => $type, '%Y' => $year, '%s' => str_pad($second, 2, 0, STR_PAD_LEFT), + '%S' => str_pad($second, 2, 0, STR_PAD_LEFT), ]; return strtr($format, $date); diff --git a/templates/CRM/Activity/Calendar/ICal.tpl b/templates/CRM/Activity/Calendar/ICal.tpl index 2ff0c050d2..b1c90b1f3f 100644 --- a/templates/CRM/Activity/Calendar/ICal.tpl +++ b/templates/CRM/Activity/Calendar/ICal.tpl @@ -16,7 +16,7 @@ BEGIN:VEVENT UID:CIVICRMACTIVITY{$activity->id} SUMMARY:{$activity->subject|crmICalText} CALSCALE:GREGORIAN -DTSTAMP;TZID={$timezone}:{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'|crmICalDate} +DTSTAMP;TZID={$timezone}:{$smarty.now|crmDate:'%Y-%m-%d %H:%M:%S'|crmICalDate} DTSTART;TZID={$timezone}:{$activity->activity_date_time|crmICalDate} DURATION:PT{$activity->duration}M {if $activity->location} diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index d82d0af535..edd12f0f57 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -127,7 +127,7 @@ {/if} {else}
{$form.start_date.label}
-
{$start_date_display|date_format}
+
{$start_date_display|crmDate:'%b %e, %Y'}
{/if}
diff --git a/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl b/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl index 372b69efe8..51d6ab1abd 100644 --- a/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl +++ b/templates/CRM/Contribute/Form/Contribution/MembershipBlock.tpl @@ -37,7 +37,7 @@
{* Lifetime memberships have no end-date so current_membership array key exists but is NULL *} {if $row.current_membership} - {if $row.current_membership|date_format:"%Y%m%d" LT $smarty.now|date_format:"%Y%m%d"} + {if $row.current_membership|crmDate:"%Y%m%d" LT $smarty.now|crmDate:"%Y%m%d"} {ts 1=$row.current_membership|crmDate 2=$row.name}Your %2 membership expired on %1.{/ts}
{else} {ts 1=$row.current_membership|crmDate 2=$row.name}Your %2 membership expires on %1.{/ts}
@@ -180,7 +180,7 @@ {* Check if there is an existing membership of this type (current_membership NOT empty) and if the end-date is prior to today. *} {if array_key_exists( 'current_membership', $row ) AND $context EQ "makeContribution" } {if $row.current_membership} - {if $row.current_membership|date_format:"%Y%m%d" LT $smarty.now|date_format:"%Y%m%d"} + {if $row.current_membership|crmDate:"%Y%m%d" LT $smarty.now|crmDate:"%Y%m%d"}
{ts 1=$row.current_membership|crmDate 2=$row.name}Your %2 membership expired on %1.{/ts} {else}
{ts 1=$row.current_membership|crmDate 2=$row.name}Your %2 membership expires on %1.{/ts} diff --git a/templates/CRM/Core/Calendar/ICal.tpl b/templates/CRM/Core/Calendar/ICal.tpl index f38502d5ad..3db616c76c 100644 --- a/templates/CRM/Core/Calendar/ICal.tpl +++ b/templates/CRM/Core/Calendar/ICal.tpl @@ -27,7 +27,7 @@ CALSCALE:GREGORIAN DTSTAMP;TZID={$timezone}:{$event.start_date|crmICalDate} DTSTART;TZID={$timezone}:{$event.start_date|crmICalDate} {else} -DTSTAMP;TZID={$timezone}:{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'|crmICalDate} +DTSTAMP;TZID={$timezone}:{$smarty.now|crmDate:'%Y-%m-%d %H:%M:%S'|crmICalDate} {/if} {if $event.end_date} DTEND;TZID={$timezone}:{$event.end_date|crmICalDate} diff --git a/templates/CRM/Core/Calendar/Rss.tpl b/templates/CRM/Core/Calendar/Rss.tpl index cc0139f1d9..ffb5259b5f 100644 --- a/templates/CRM/Core/Calendar/Rss.tpl +++ b/templates/CRM/Core/Calendar/Rss.tpl @@ -27,8 +27,8 @@ {/if} {if $event.start_date}{ts}When{/ts}: {$event.start_date|crmDate}{if $event.end_date} {ts}through{/ts} {strip} {* Only show end time if end date = start date *} - {if $event.end_date|date_format:"%Y%m%d" == $event.start_date|date_format:"%Y%m%d"} - {$event.end_date|date_format:"%I:%M %p"} + {if $event.end_date|crmDate:"%Y%m%d" == $event.start_date|crmDate:"%Y%m%d"} + {$event.end_date|crmDate:"%I:%M %p"} {else} {$event.end_date|crmDate} {/if}{/strip} diff --git a/templates/CRM/Event/Form/Registration/EventInfoBlock.tpl b/templates/CRM/Event/Form/Registration/EventInfoBlock.tpl index 8a0486b4c2..c75be4e1d3 100644 --- a/templates/CRM/Event/Form/Registration/EventInfoBlock.tpl +++ b/templates/CRM/Event/Form/Registration/EventInfoBlock.tpl @@ -24,7 +24,7 @@ {if $event.event_end_date}   {ts}through{/ts}   {* Only show end time if end date = start date *} - {if $event.event_end_date|date_format:"%Y%m%d" == $event.event_start_date|date_format:"%Y%m%d"} + {if $event.event_end_date|crmDate:"%Y%m%d" == $event.event_start_date|crmDate:"%Y%m%d"} {$event.event_end_date|crmDate:0:1} {else} {$event.event_end_date|crmDate} diff --git a/templates/CRM/Event/Form/Selector.tpl b/templates/CRM/Event/Form/Selector.tpl index a09a6d3567..1461fc4d53 100644 --- a/templates/CRM/Event/Form/Selector.tpl +++ b/templates/CRM/Event/Form/Selector.tpl @@ -60,7 +60,7 @@ {$row.participant_fee_amount|crmMoney:$row.participant_fee_currency} {$row.participant_register_date|truncate:10:''|crmDate} {$row.event_start_date|truncate:10:''|crmDate} - {if $row.event_end_date && $row.event_end_date|date_format:"%Y%m%d" NEQ $row.event_start_date|date_format:"%Y%m%d"} + {if $row.event_end_date && $row.event_end_date|crmDate:"%Y%m%d" NEQ $row.event_start_date|crmDate:"%Y%m%d"}
- {$row.event_end_date|truncate:10:''|crmDate} {/if} diff --git a/templates/CRM/Event/Form/Task/Print.tpl b/templates/CRM/Event/Form/Task/Print.tpl index 013cf6fd28..689580967b 100644 --- a/templates/CRM/Event/Form/Task/Print.tpl +++ b/templates/CRM/Event/Form/Task/Print.tpl @@ -43,7 +43,7 @@ {/if} {$row.participant_fee_amount|crmMoney} {$row.event_start_date|truncate:10:''|crmDate} - {if $row.event_end_date && $row.event_end_date|date_format:"%Y%m%d" NEQ $row.event_start_date|date_format:"%Y%m%d"} + {if $row.event_end_date && $row.event_end_date|crmDate:"%Y%m%d" NEQ $row.event_start_date|crmDate:"%Y%m%d"}
- {$row.event_end_date|truncate:10:''|crmDate} {/if} diff --git a/templates/CRM/Event/Page/EventInfo.tpl b/templates/CRM/Event/Page/EventInfo.tpl index 8315c22131..55efe2c6ae 100644 --- a/templates/CRM/Event/Page/EventInfo.tpl +++ b/templates/CRM/Event/Page/EventInfo.tpl @@ -106,7 +106,7 @@ {if $event.event_end_date}  {ts}through{/ts}  {* Only show end time if end date = start date *} - {if $event.event_end_date|date_format:"%Y%m%d" == $event.event_start_date|date_format:"%Y%m%d"} + {if $event.event_end_date|crmDate:"%Y%m%d" == $event.event_start_date|crmDate:"%Y%m%d"} {$event.event_end_date|crmDate:0:1} {else} {$event.event_end_date|crmDate} diff --git a/templates/CRM/Event/Page/List.tpl b/templates/CRM/Event/Page/List.tpl index 50da60fd8b..5d2d839ceb 100644 --- a/templates/CRM/Event/Page/List.tpl +++ b/templates/CRM/Event/Page/List.tpl @@ -32,7 +32,7 @@ {if $event.start_date}{$event.start_date|crmDate}{if $event.end_date}
{ts}through{/ts}
{strip} {* Only show end time if end date = start date *} - {if $event.end_date|date_format:"%Y%m%d" == $event.start_date|date_format:"%Y%m%d"} + {if $event.end_date|crmDate:"%Y%m%d" == $event.start_date|crmDate:"%Y%m%d"} {$event.end_date|crmDate:0:1} {else} {$event.end_date|crmDate} diff --git a/templates/CRM/Event/Page/UserDashboard.tpl b/templates/CRM/Event/Page/UserDashboard.tpl index 210ece0034..6ceeff6ad8 100644 --- a/templates/CRM/Event/Page/UserDashboard.tpl +++ b/templates/CRM/Event/Page/UserDashboard.tpl @@ -31,7 +31,7 @@ {if $row.event_end_date}   -   {* Only show end time if end date = start date *} - {if $row.event_end_date|date_format:"%Y%m%d" == $row.event_start_date|date_format:"%Y%m%d"} + {if $row.event_end_date|crmDate:"%Y%m%d" == $row.event_start_date|crmDate:"%Y%m%d"} {$row.event_end_date|crmDate:0:1} {else} {$row.event_end_date|crmDate} diff --git a/templates/CRM/common/l10n.js.tpl b/templates/CRM/common/l10n.js.tpl index 67f69ada05..03598223d7 100644 --- a/templates/CRM/common/l10n.js.tpl +++ b/templates/CRM/common/l10n.js.tpl @@ -7,7 +7,7 @@ | and copyright information, see https://civicrm.org/licensing | +--------------------------------------------------------------------+ *}// http://civicrm.org/licensing -//