Skip to content

Commit 18fc2e8

Browse files
committed
[FIX] PHP 8.1 Deprecated: Function strftime() is deprecated in settings and dataGrid
1 parent 244e677 commit 18fc2e8

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

core/src/Core.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4637,28 +4637,43 @@ public function toDateFormat($timestamp = 0, $mode = '')
46374637
if (extension_loaded('intl')) {
46384638
// https://www.php.net/manual/en/class.intldateformatter.php
46394639
// https://www.php.net/manual/en/datetime.createfromformat.php
4640+
$dateFormat = str_replace(
4641+
['%Y', '%m', '%d', '%I', '%H', '%M', '%S', '%p'],
4642+
['Y', 'MM', 'dd', 'h', 'hh', 'mm', 'ss', 'a'],
4643+
$dateFormat
4644+
);
46404645
if (empty($mode)) {
46414646
$formatter = new IntlDateFormatter(
46424647
$this->getConfig('manager_language'),
4643-
IntlDateFormatter::MEDIUM,
4644-
IntlDateFormatter::MEDIUM,
4648+
IntlDateFormatter::FULL,
4649+
IntlDateFormatter::FULL,
46454650
null,
46464651
null,
4647-
$this->getConfig('datetime_format') . " hh:mm:ss"
4652+
$dateFormat . " hh:mm:ss"
46484653
);
46494654
$strTime = $formatter->format($timestamp);
46504655
} elseif ($mode === 'dateOnly') {
46514656
$formatter = new IntlDateFormatter(
46524657
$this->getConfig('manager_language'),
4653-
IntlDateFormatter::MEDIUM,
4658+
IntlDateFormatter::FULL,
46544659
IntlDateFormatter::NONE,
46554660
null,
46564661
null,
4657-
$this->getConfig('datetime_format')
4662+
$dateFormat
4663+
);
4664+
$strTime = $formatter->format($timestamp);
4665+
} elseif ($mode === 'timeOnly') {
4666+
$formatter = new IntlDateFormatter(
4667+
$this->getConfig('manager_language'),
4668+
IntlDateFormatter::NONE,
4669+
IntlDateFormatter::MEDIUM,
4670+
null,
4671+
null,
4672+
"hh:mm:ss"
46584673
);
46594674
$strTime = $formatter->format($timestamp);
46604675
} elseif ($mode === 'formatOnly') {
4661-
$strTime = $this->getConfig('datetime_format');
4676+
$strTime = $dateFormat;
46624677
}
46634678
} else {
46644679
if (empty($mode)) {

core/src/Support/DataGrid.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use EvolutionCMS\Interfaces\DataGridInterface;
44
use Illuminate\Database\Query\Builder;
5+
use IntlDateFormatter;
56

67
#
78
# DataGrid Class
@@ -304,7 +305,27 @@ public function formatColumnValue($row, $value, $type, &$align)
304305
if (!$type_format) {
305306
$type_format = "%A %d, %B %Y";
306307
}
307-
$value = strftime($type_format, $value);
308+
if (extension_loaded('intl')) {
309+
// https://www.php.net/manual/en/class.intldateformatter.php
310+
// https://www.php.net/manual/en/datetime.createfromformat.php
311+
$type_format = str_replace(
312+
['%Y', '%m', '%d', '%I', '%H', '%M', '%S', '%p'],
313+
['Y', 'MM', 'dd', 'h', 'hh', 'mm', 'ss', 'a'],
314+
$type_format
315+
);
316+
317+
$formatter = new IntlDateFormatter(
318+
evolutionCMS()->getConfig('manager_language'),
319+
IntlDateFormatter::FULL,
320+
IntlDateFormatter::FULL,
321+
null,
322+
null,
323+
$type_format . " hh:mm:ss"
324+
);
325+
$value = $formatter->format($value);
326+
} else {
327+
$value = strftime($type_format, $value);
328+
}
308329
break;
309330

310331
case "boolean":

manager/views/page/eventlog.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function menuAction(a)
165165
$grd->columns = ManagerTheme::getLexicon('type') . " ," . ManagerTheme::getLexicon('source') . " ," . ManagerTheme::getLexicon('date') . " ," . ManagerTheme::getLexicon('event_id') . " ," . ManagerTheme::getLexicon('sysinfo_userid');
166166
$grd->colWidths = "1%,,1%,1%,1%";
167167
$grd->colAligns = "center,,,center,center";
168-
$grd->colTypes = "template:<a class='gridRowIcon' href='javascript:;' onclick='return showContentMenu([+id+],event);' title='" . ManagerTheme::getLexicon('click_to_context') . "'><i class='[+icon+]'></i></a>||template:<a href='index.php?a=115&id=[+id+]' title='" . ManagerTheme::getLexicon('click_to_view_details') . "'>[+source+]</a>||date: " . $modx->toDateFormat(null, 'formatOnly') . ' %I:%M %p';
168+
$grd->colTypes = "template:<a class='gridRowIcon' href='javascript:;' onclick='return showContentMenu([+id+],event);' title='" . ManagerTheme::getLexicon('click_to_context') . "'><i class='[+icon+]'></i></a>||template:<a href='index.php?a=115&id=[+id+]' title='" . ManagerTheme::getLexicon('click_to_view_details') . "'>[+source+]</a>||date: " . $modx->toDateFormat(null, 'formatOnly');
169169
if ($listmode == '1') {
170170
$grd->pageSize = 0;
171171
}

manager/views/page/system_settings/general.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@
475475
'value' => $settings['server_offset_time'],
476476
'options' => $serverTimes,
477477
'attributes' => 'onChange="documentDirty=true;" size="1"',
478-
'comment' => sprintf(ManagerTheme::getLexicon('serveroffset_message'), strftime('%H:%M:%S', time()), strftime('%H:%M:%S', time() + $settings['server_offset_time']))
478+
'comment' => sprintf(ManagerTheme::getLexicon('serveroffset_message'), evolutionCMS()->toDateFormat(time(), 'timeOnly'), evolutionCMS()->toDateFormat(time() + $settings['server_offset_time'], 'timeOnly'))
479479
])
480480

481481
<div class="split my-1"></div>

0 commit comments

Comments
 (0)