From fb7d34f69a0e47643c1e16c9e3d72dbc74b4bc4d Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Wed, 16 Oct 2019 01:21:01 +0200 Subject: Use strftime() with locale support This commit changes the parseDatetime() function to use strftime() with locale support to replace the day-and-month name related parts within the format string. The strftime() function uses the locale defined by the LC_TIME or LC_ALL environment variable which can be set with PHPs own setlocale() function within the configuration.php. --- core/configuration-example.php | 2 ++ core/functions.php | 33 ++++----------------------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/core/configuration-example.php b/core/configuration-example.php index 4378d46..f87117b 100644 --- a/core/configuration-example.php +++ b/core/configuration-example.php @@ -13,6 +13,8 @@ # # #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%# +# setlocale(LC_TIME, ['en_US.utf8', 'en_US']); + Application::set('CORE.LANGUAGE', 'en'); Application::set('BLOGMETA.NAME', 'My Techblog'); Application::set('BLOGMETA.DESC', '[a creative description]'); diff --git a/core/functions.php b/core/functions.php index 1e786ed..ac4478f 100644 --- a/core/functions.php +++ b/core/functions.php @@ -107,37 +107,12 @@ function generateItemTemplateData(Item $Item): array { # Parser for datetime formatted strings [YYYY-MM-DD HH:II:SS] #=============================================================================== function parseDatetime($datetime, $format): string { - $Language = Application::getLanguage(); - list($date, $time) = explode(' ', $datetime); list($DATE['Y'], $DATE['M'], $DATE['D']) = explode('-', $date); list($TIME['H'], $TIME['M'], $TIME['S']) = explode(':', $time); - $M_LIST = [ - '01' => $Language->text('month_01'), - '02' => $Language->text('month_02'), - '03' => $Language->text('month_03'), - '04' => $Language->text('month_04'), - '05' => $Language->text('month_05'), - '06' => $Language->text('month_06'), - '07' => $Language->text('month_07'), - '08' => $Language->text('month_08'), - '09' => $Language->text('month_09'), - '10' => $Language->text('month_10'), - '11' => $Language->text('month_11'), - '12' => $Language->text('month_12'), - ]; - - $D_LIST = [ - 0 => $Language->text('day_6'), - 1 => $Language->text('day_0'), - 2 => $Language->text('day_1'), - 3 => $Language->text('day_2'), - 4 => $Language->text('day_3'), - 5 => $Language->text('day_4'), - 6 => $Language->text('day_5'), - ]; + $unixtime = strtotime($datetime); return strtr($format, [ '[Y]' => $DATE['Y'], @@ -146,11 +121,11 @@ function parseDatetime($datetime, $format): string { '[H]' => $TIME['H'], '[I]' => $TIME['M'], '[S]' => $TIME['S'], - '[W]' => $D_LIST[date('w', strtotime($datetime))], - '[F]' => $M_LIST[date('m', strtotime($datetime))], + '[W]' => strftime('%A', $unixtime), + '[F]' => strftime('%B', $unixtime), '[DATE]' => $date, '[TIME]' => $time, - '[RFC2822]' => date('r', strtotime($datetime)) + '[RFC2822]' => date('r', $unixtime) ]); } -- cgit v1.2.3