Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] [PHP8.1] Replace usage of smarty's date_filter to ensure we don't call s… #23800

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CRM/Core/Smarty/plugins/modifier.crmDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
3 changes: 2 additions & 1 deletion CRM/Utils/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public static function customFormat($dateString, $format = NULL, $dateParts = NU

$hour24 = (int) substr($dateString, 11, 2);
$minute = (int) substr($dateString, 14, 2);
$second = (int) substr($dateString, 16, 2);
$second = (int) substr($dateString, 17, 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was only just added in the rc - if it is wrong then we should change this line in the rc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(note the passive voice - had it been correct I could have said 'I added it' but since it seems It might be wrong.....)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't have noticed in my testing since the import wouldn't hit that line but yes it seems like it should be 17.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have said 'it was not noticed' :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe. Yes one could have said that.

}
else {
$year = (int) substr($dateString, 0, 4);
Expand Down Expand Up @@ -433,6 +433,7 @@ public static function customFormat($dateString, $format = NULL, $dateParts = NU
'%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);
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Activity/Calendar/ICal.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Contribute/Form/Contribution/Main.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
{/if}
{else}
<div class="label">{$form.start_date.label}</div>
<div class="content">{$start_date_display|date_format}</div>
<div class="content">{$start_date_display|crmDate:'%b %e, %Y'}</div>
{/if}
<div class="clear"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<div id='help'>
{* 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 <strong>%2</strong> membership expired on %1.{/ts}<br />
{else}
{ts 1=$row.current_membership|crmDate 2=$row.name}Your <strong>%2</strong> membership expires on %1.{/ts}<br />
Expand Down Expand Up @@ -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"}
<br /><em>{ts 1=$row.current_membership|crmDate 2=$row.name}Your <strong>%2</strong> membership expired on %1.{/ts}</em>
{else}
<br /><em>{ts 1=$row.current_membership|crmDate 2=$row.name}Your <strong>%2</strong> membership expires on %1.{/ts}</em>
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Core/Calendar/ICal.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions templates/CRM/Core/Calendar/Rss.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also slightly different, e.g. 12:13 PM vs 12:13 pm. But I don't think that would be confusing, and it's unlikely people have automated scripts that are parsing this or something.

{else}
{$event.end_date|crmDate}
{/if}{/strip}
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Event/Form/Registration/EventInfoBlock.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{if $event.event_end_date}
&nbsp; {ts}through{/ts} &nbsp;
{* 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}
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Event/Form/Selector.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<td class="right nowrap crm-participant-participant_fee_amount">{$row.participant_fee_amount|crmMoney:$row.participant_fee_currency}</td>
<td class="crm-participant-participant_register_date">{$row.participant_register_date|truncate:10:''|crmDate}</td>
<td class="crm-participant-event_start_date">{$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"}
<br/>- {$row.event_end_date|truncate:10:''|crmDate}
{/if}
</td>
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Event/Form/Task/Print.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{/if}
<td class="crm-event-print-event_participant_fee_amount">{$row.participant_fee_amount|crmMoney}</td>
<td class="crm-event-print-event_date">{$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"}
<br/>- {$row.event_end_date|truncate:10:''|crmDate}
{/if}
</td>
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Event/Page/EventInfo.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
{if $event.event_end_date}
&nbsp;{ts}through{/ts}&nbsp;
{* 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}
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Event/Page/List.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<td class="nowrap" data-order="{$event.start_date|crmDate:'%Y-%m-%d'}">
{if $event.start_date}{$event.start_date|crmDate}{if $event.end_date}<br /><em>{ts}through{/ts}</em><br />{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}
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Event/Page/UserDashboard.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{if $row.event_end_date}
&nbsp; - &nbsp;
{* 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}
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/common/l10n.js.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}// http://civicrm.org/licensing
// <script> Generated {$smarty.now|date_format:'%d %b %Y %H:%M:%S'}
// <script> Generated {$smarty.now|crmDate:'%d %b %Y %H:%M:%S'}
{* This file should only contain strings and settings which rarely change *}
(function($) {ldelim}
// Config settings
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/common/navigation.js.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</li>
{$navigation}
</ul>
{/strip}{/capture}// <script> Generated {$smarty.now|date_format:'%d %b %Y %H:%M:%S'}
{/strip}{/capture}// <script> Generated {$smarty.now|crmDate:'%d %b %Y %H:%M:%S'}
{literal}
(function($) {
var menuMarkup = {/literal}{$menuMarkup|@json_encode}{literal};
Expand Down