From 4be1f6ae90e66c6df23cd6b61911b277df4886fa Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Wed, 9 Sep 2020 17:52:11 +0200 Subject: [PATCH] Try to proberly encode formatted date strings returned by strftime() Fixes #560 --- composer.json | 1 + lib/Pico.php | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 02b45aa..b9ff27c 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,7 @@ }, "require": { "php": ">=5.3.6", + "ext-mbstring": "*", "twig/twig": "^1.36", "symfony/yaml" : "^2.8", "erusev/parsedown": "1.8.0-beta-7", diff --git a/lib/Pico.php b/lib/Pico.php index ae53e68..f6384f9 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -1518,8 +1518,17 @@ class Pico } if (empty($meta['date_formatted'])) { - $dateFormat = $this->getConfig('date_format'); - $meta['date_formatted'] = $meta['time'] ? utf8_encode(strftime($dateFormat, $meta['time'])) : ''; + if ($meta['time']) { + $encodingList = mb_detect_order(); + if ($encodingList === array('ASCII', 'UTF-8')) { + $encodingList[] = 'Windows-1252'; + } + + $rawFormattedDate = strftime($this->getConfig('date_format'), $meta['time']); + $meta['date_formatted'] = mb_convert_encoding($rawFormattedDate, 'UTF-8', $encodingList); + } else { + $meta['date_formatted'] = ''; + } } } else { // guarantee array key existance