Skip to content

Commit

Permalink
PHP 8.1: strftime and gmstrftime functions are deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
nczirjak-acdh committed Aug 4, 2022
1 parent 7d45426 commit a290ceb
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 31 deletions.
26 changes: 6 additions & 20 deletions src/TwigExtension/ArcheTwigDateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function getFilters()
if ($this->checkYearIsMoreThanFourDigit($value)) {
return $this->notNormalDate($value, $lang, $dateformat);
}
return $this->returnFormattedDate($this->extendDateFormat($dateformat), $value, $lang);
return $this->returnFormattedDate($dateformat, $value, $lang);
})
];
}
Expand All @@ -25,20 +25,6 @@ public function getName()
return 'acdh_repo_gui.twig_extension';
}

/**
* change the datefomat to work with strftime
*
* @param string $dateformat
* @return string
*/
private function extendDateFormat(string $dateFormat): string
{
$search = array('Y', 'y', 'M', 'm', 'D', 'd');
$replace = array('%Y', '%y', '%b', '%m', '%d', '%d');

return str_replace($search, $replace, $dateFormat);
}

private function checkYearIsMoreThanFourDigit($value): bool
{
$explode = explode("-", $value);
Expand All @@ -57,13 +43,13 @@ private function checkYearIsMoreThanFourDigit($value): bool
*/
private function returnFormattedDate($dateformat, $value, $lang): string
{
$cal = \IntlCalendar::fromDateTime($value." Europe/Vienna");
if ($lang == 'de') {
setlocale(LC_TIME, 'de_DE.utf8');
return strftime($dateformat, strtotime($value));
return \IntlDateFormatter::formatObject($cal, $dateformat, 'de_DE');
}

setlocale(LC_TIME, 'en_US.utf8');
return strftime($dateformat, strtotime($value));
return \IntlDateFormatter::formatObject($cal, $dateformat, 'en_US');
//setlocale(LC_TIME, 'en_US.utf8');
//return strftime($dateformat, strtotime($value));
}


Expand Down
2 changes: 1 addition & 1 deletion templates/acdh-repo-gui-child.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<span class="res-prop-label">{{ "Available Date"|trans }}:</span>

{{ include('/modules/contrib/arche-gui/templates/helpers/helper-date.html.twig',
{'value': item.getData('acdh:hasAvailableDate')[0], 'dateformat': 'd M Y' } ) }}
{'value': item.getData('acdh:hasAvailableDate')[0], 'dateformat': 'd MMM Y' } ) }}

{% endif%}
{% if item.getData('acdh:hasAvailableDate')[0].value and item.getData('acdh:hasVersion')[0].value %}
Expand Down
6 changes: 3 additions & 3 deletions templates/acdh-repo-gui-detail-basic.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@
'icon': 'today',
'label': 'Created Start Date',
'type': 'date',
'dateformat': 'd M Y'
'dateformat': 'd MMM Y'
},
'acdh:hasCreatedEndDate': {
'icon': 'today',
'label': 'Created End Date',
'type': 'date',
'dateformat': 'd M Y'
'dateformat': 'd MMM Y'
},
'acdh:hasAvailableDate': {
'icon': 'today',
'label': 'Available Date',
'type': 'date',
'dateformat': 'd M Y'
'dateformat': 'd MMM Y'
},
'acdh:hasExtent': {
'icon': 'dehaze',
Expand Down
4 changes: 2 additions & 2 deletions templates/acdh-repo-gui-detail-project.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ set properties = {
'icon': 'today',
'label': 'Start Date',
'type': 'date',
'dateformat': 'd M Y'
'dateformat': 'd MMM Y'
},
'acdh:hasEndDate': {
'icon': 'today',
'label': 'End Date',
'type': 'date',
'dateformat': 'd M Y'
'dateformat': 'd MMM Y'
},
'acdh:hasLanguage': {
'icon': 'flag',
Expand Down
2 changes: 1 addition & 1 deletion templates/acdh-repo-gui-detail-versions-block.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{% for key, value in result %}
{% set versionTxt = '' %}
<div class="pl-2 pb-1 arche-versions-row {{ value.actual }}">
<i class="material-icons" style="font-size:14px !important" >layers</i>&nbsp;<a href="/browser/oeaw_detail/{{ value.id }}">{{ versionTxt|trans }} {{ value.avdate|date('d M Y') }} &ndash; {{ value.version }}</a>
<i class="material-icons" style="font-size:14px !important" >layers</i>&nbsp;<a href="/browser/oeaw_detail/{{ value.id }}">{{ versionTxt|trans }} {{ value.avdate|date('d MMM Y') }} &ndash; {{ value.version }}</a>
</div>
{% endfor %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/acdh-repo-gui-main-page-left-block.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{% if item.getData('acdh:hasAvailableDate') %}
{{ item.getPropTitle('acdh:hasAvailableDate') }}
<div class="res-property">
{{ include('/modules/contrib/arche-gui/templates/helper-displayFields.html.twig', {'data': item.getData('acdh:hasAvailableDate') , 'icon': 'today', 'type': 'date', 'dateformat': "d M Y", 'label': "Available Date" } ) }}
{{ include('/modules/contrib/arche-gui/templates/helper-displayFields.html.twig', {'data': item.getData('acdh:hasAvailableDate') , 'icon': 'today', 'type': 'date', 'dateformat': "d MMM Y", 'label': "Available Date" } ) }}
</div>
{% endif%}

Expand Down
2 changes: 1 addition & 1 deletion templates/acdh-repo-gui-main.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{% if item.getData('acdh:hasAvailableDate') %}
{{ item.getPropTitle('acdh:hasAvailableDate') }}
<div class="res-property">
{{ include('/modules/contrib/arche-gui/templates/helper-displayFields.html.twig', {'data': item.getData('acdh:hasAvailableDate') , 'icon': 'today', 'dateformat': "d M Y", 'label': "Available Date", 'type': 'date' } ) }}
{{ include('/modules/contrib/arche-gui/templates/helper-displayFields.html.twig', {'data': item.getData('acdh:hasAvailableDate') , 'icon': 'today', 'dateformat': "d MMM Y", 'label': "Available Date", 'type': 'date' } ) }}
</div>
{% endif%}
{% endif%}
Expand Down
2 changes: 1 addition & 1 deletion templates/acdh-repo-gui-search-full.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{% if item.getData('acdh:hasAvailableDate') %}
{{ item.getPropTitle('acdh:hasAvailableDate') }}
<div class="res-property">
{{ include('/modules/contrib/arche-gui/templates/helper-displayFields.html.twig', {'data': item.getData('acdh:hasAvailableDate') , 'icon': 'today', 'dateformat': "d M Y", 'label': "Available Date", 'type': 'date' } ) }}
{{ include('/modules/contrib/arche-gui/templates/helper-displayFields.html.twig', {'data': item.getData('acdh:hasAvailableDate') , 'icon': 'today', 'dateformat': "d MMM Y", 'label': "Available Date", 'type': 'date' } ) }}
</div>
{% endif%}
{% endif%}
Expand Down
2 changes: 1 addition & 1 deletion templates/helper-displayFields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Field extra type:
- delimiter (optional): basic is ",", you can use also "<br>"
- icon: the fontawesome icon name, what will be displayed before the label
- label: the label what should be displayed before the value
- dateformat (required just for the date type): f.e: 'd M Y'
- dateformat (required just for the date type): f.e: 'd MMM Y'
-->

Expand Down

0 comments on commit a290ceb

Please sign in to comment.