From 1ca2d0913755f9f66ecd0a92c8dcbebc452ed4cb Mon Sep 17 00:00:00 2001 From: ruan <2369127-ruany@users.noreply.gitlab.com> Date: Thu, 30 Dec 2021 11:10:39 +0200 Subject: [PATCH] Remove deprecated functions (https://php.watch/versions/8.1/strftime-gmstrftime-deprecated) --- inc/page.php | 3 ++- inc/settings.php | 27 +++------------------------ 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/inc/page.php b/inc/page.php index a028f82..ed591cc 100644 --- a/inc/page.php +++ b/inc/page.php @@ -394,7 +394,8 @@ class Page { */ function millis_to_date($millis) { $ts = $millis / 1000; - $result = strftime($this->settings->date_format, $ts); + $formatter = new IntlDateFormatter($this->settings->lang, IntlDateFormatter::LONG, IntlDateFormatter::NONE, $this->settings->timezone, IntlDateFormatter::GREGORIAN, $this->settings->date_format); + $result = $formatter->format($ts); $translations = $this->settings->date_month_translations; if ($translations !== null) { foreach ($translations as $key => $val) { diff --git a/inc/settings.php b/inc/settings.php index 2e9921b..831e615 100644 --- a/inc/settings.php +++ b/inc/settings.php @@ -52,9 +52,9 @@ class Settings { $this->timezone = "UTC"; // The date format can be changed here. - // https://secure.php.net/manual/en/function.strftime.php - // Example output of default format: July 2, 2015, 09:19; August 4, 2016, 18:37 - $this->date_format = '%B %d, %Y, %H:%M'; + // https://unicode-org.github.io/icu/userguide/format_parse/datetime/#date-field-symbol-table + // Example output of default format: July 2, 2015, 09:19 + $this->date_format = 'MMMM d, yyyy, HH:mm'; // Amount of bans/mutes/warnings to show on each page $this->limit_per_page = 10; @@ -161,8 +161,6 @@ class Settings { } $this->verify = false; - $this->test_strftime(); - $this->init_tables(); if ($connect) { @@ -256,25 +254,6 @@ class Settings { die("Database error"); } - private function test_strftime() { - $test = gmstrftime($this->date_format, 0); - if ($test == false) { - ob_start(); - var_dump($test); - $testdump = ob_get_clean(); - die("Error: date_format test failed. gmstrftime(\"" . $this->date_format . "\",0) returned $testdump"); - } - - $test = gmstrftime("%Y-%m-%d %H:%M", 0); - if ($test !== "1970-01-01 00:00") { - ob_start(); - var_dump($test); - $testdump = ob_get_clean(); - die("Assertion failed: gmstrftime(\"%Y-%m-%d %H:%M\",0) != \"1970-01-01 00:00\"
Actual result: $testdump"); - } - } - - protected function init_tables() { $this->table = array(); foreach (array('bans', 'mutes', 'warnings', 'kicks', 'history', 'servers', 'config') as $t) {