aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2019-10-16 01:21:01 +0200
committerThomas Lange <code@nerdmind.de>2019-10-16 01:21:01 +0200
commitfb7d34f69a0e47643c1e16c9e3d72dbc74b4bc4d (patch)
tree5bdf061771bd66c6527b8522ab7c8de0d4c43a6f
parente3658b5cf4c70e0b7f910777d08a4cea19b163e4 (diff)
downloadblog-fb7d34f69a0e47643c1e16c9e3d72dbc74b4bc4d.tar.gz
blog-fb7d34f69a0e47643c1e16c9e3d72dbc74b4bc4d.tar.xz
blog-fb7d34f69a0e47643c1e16c9e3d72dbc74b4bc4d.zip
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.
-rw-r--r--core/configuration-example.php2
-rw-r--r--core/functions.php33
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)
]);
}