From e8251ade6ab35880d28809e5ce69cef18c3f9d8a Mon Sep 17 00:00:00 2001 From: discomrade Date: Sat, 5 Feb 2022 00:11:13 -0100 Subject: [PATCH] Change dates to ISO 8601-like, fix deprecation of strfdate() in PHP 8.1, fix non-GMT dates Unfortunately this means there are two format strings needed when using JS for local time. --- inc/announcements.php | 6 ++--- inc/config.php | 24 +++++++++++-------- .../twig/extensions/Extension/Tinyboard.php | 2 +- inc/mod/pages.php | 4 ++-- templates/important.html | 2 +- templates/main.js | 2 +- templates/post/time.html | 2 +- templates/themes/catalog/catalog.html | 2 +- templates/themes/sitemap/sitemap.xml | 2 +- tools/public_statistics_cli.php | 2 +- 10 files changed, 26 insertions(+), 22 deletions(-) diff --git a/inc/announcements.php b/inc/announcements.php index 1c3eb8ec..47951ec4 100644 --- a/inc/announcements.php +++ b/inc/announcements.php @@ -64,7 +64,7 @@ class Announcements { $announcements = $query->fetchAll(PDO::FETCH_ASSOC); foreach ($announcements as &$announce) { - $announce['date_formated'] = strftime($config['announcements']['date_format'], $announce['date']); + $announce['date_formated'] = gmdate($config['announcements']['date_format'], $announce['date']); } $announcements_short = Element('announcements.html', array( @@ -89,7 +89,7 @@ class Announcements { $announcements = $query->fetchAll(PDO::FETCH_ASSOC); foreach ($announcements as &$announce) { - $announce['date_formated'] = strftime($config['announcements']['date_format'], $announce['date']); + $announce['date_formated'] = gmdate($config['announcements']['date_format'], $announce['date']); } // Generate page for full list of announcements @@ -137,7 +137,7 @@ class Announcements { if($filter_staff) $announce['username'] = '?'; - $announce['date_formated'] = strftime($date_format, $announce['date']); + $announce['date_formated'] = gmdate($date_format, $announce['date']); $json = json_encode($announce); $out ? fputs($out, $json) : print($json); diff --git a/inc/config.php b/inc/config.php index 94c411a6..46de19c9 100644 --- a/inc/config.php +++ b/inc/config.php @@ -987,7 +987,7 @@ $config['announcements']['show_count'] = 3; // Date format for announcements. - $config['announcements']['date_format'] = '%m/%d/%Y'; + $config['announcements']['date_format'] = 'Y-m-d'; // Create full announcements page. $config['announcements']['page'] = true; @@ -1006,11 +1006,16 @@ // Timezone to use for displaying dates/times. $config['timezone'] = 'America/Los_Angeles'; - // The format string passed to strftime() for displaying dates. - // http://www.php.net/manual/en/function.strftime.php - $config['post_date'] = '%m/%d/%y (%a) %H:%M:%S'; - // Same as above, but used for "you are banned' pages. - $config['ban_date'] = '%A %e %B, %Y'; + // The format string passed to date() for displaying dates. + // https://www.php.net/manual/en/datetime.format.php + $config['post_date'] = 'Y-m-d (D) H:i:s'; + // The format string passed to JavaScript's strfdate() for displaying local dates. + // https://www.php.net/manual/en/function.strftime.php + $config['post_date_js'] = '%F (%a) %T'; + // Same as above, but used for catalog tooltips. + $config['catalog_date'] = 'M d H:i'; + // Same as above, but used for 'you are banned' pages. + $config['ban_date'] = 'l j F, Y'; // The names on the post buttons. (On most imageboards, these are both just "Post"). $config['button_newtopic'] = _('New Topic'); @@ -2044,10 +2049,9 @@ $config['public_stats']['hourly'] = false; // Include the current hour in public stats. $config['public_stats']['realtime'] = false; - // The format string passed to strftime() for displaying dates. - // http://www.php.net/manual/en/function.strftime.php - //$config['public_stat']['date'] = '%m/%d/%y (%a) %l %P'; - $config['public_stats']['date'] = ''; + // The format string passed to date() for displaying dates. + // https://www.php.net/manual/en/datetime.format.php + $config['public_stats']['date'] = 'Y-m-d\TH:i:s\Z'; /* * ==================== diff --git a/inc/lib/twig/extensions/Extension/Tinyboard.php b/inc/lib/twig/extensions/Extension/Tinyboard.php index c14d1523..c2c78ce4 100644 --- a/inc/lib/twig/extensions/Extension/Tinyboard.php +++ b/inc/lib/twig/extensions/Extension/Tinyboard.php @@ -81,7 +81,7 @@ function twig_remove_whitespace_filter($data) { } function twig_date_filter($date, $format) { - return gmstrftime($format, $date); + return gmdate($format, $date); } function twig_hasPermission_filter($mod, $permission, $board = null) { diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 00f73ca1..17135491 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1010,7 +1010,7 @@ function mod_announcements() { $announcements = $query->fetchAll(PDO::FETCH_ASSOC); foreach ($announcements as &$announce) { - $announce['date_formated'] = strftime($config['announcements']['date_format'], $announce['date']); + $announce['date_formated'] = gmdate($config['announcements']['date_format'], $announce['date']); } // Display announcement page @@ -3408,7 +3408,7 @@ function mod_config($board_config = false) { } if (!empty($config_append)) { - $config_append = "\n// Changes made via web editor by \"" . $mod['username'] . "\" @ " . date('r') . ":\n" . $config_append . "\n"; + $config_append = "\n// Changes made via web editor by \"" . $mod['username'] . "\" @ " . gmdate('r') . ":\n" . $config_append . "\n"; if (!is_file($config_file)) $config_append = " {% for telegram in telegrams %}
- +

{{ telegram.message }}


diff --git a/templates/main.js b/templates/main.js index a4352ee1..fbdc35e9 100644 --- a/templates/main.js +++ b/templates/main.js @@ -406,7 +406,7 @@ function ready() { {% endverbatim %} -var post_date = "{{ config.post_date }}"; +var post_date = "{{ config.post_date_js }}"; var max_images = {{ config.max_images }}; onready(init); diff --git a/templates/post/time.html b/templates/post/time.html index e6273f94..180f0eef 100644 --- a/templates/post/time.html +++ b/templates/post/time.html @@ -1 +1 @@ - + diff --git a/templates/themes/catalog/catalog.html b/templates/themes/catalog/catalog.html index 7b5c9d42..cf466f0d 100644 --- a/templates/themes/catalog/catalog.html +++ b/templates/themes/catalog/catalog.html @@ -62,7 +62,7 @@ {% else %} + id="img-{{ post.id }}" data-subject="{% if post.subject %}{{ post.subject|e }}{% endif %}" data-name="{{ post.name|e }}" data-muhdifference="{{ post.muhdifference }}" class="{{post.board}} thread-image" title="{{post.bump|date(config.catalog_date)}}">
diff --git a/templates/themes/sitemap/sitemap.xml b/templates/themes/sitemap/sitemap.xml index 95dfdd26..d1569b7b 100644 --- a/templates/themes/sitemap/sitemap.xml +++ b/templates/themes/sitemap/sitemap.xml @@ -10,7 +10,7 @@ {% for thread in thread_list %} {{ settings.url ~ (config.board_path | format(board)) ~ config.dir.res ~ link_for(thread) }} - {{ thread.lastmod | date('%Y-%m-%dT%H:%M:%S') }}{{ timezone() }} + {{ thread.lastmod | date('Y-m-d\\TH:i:s') }}{{ timezone() }} {{ settings.changefreq }} {% endfor %} diff --git a/tools/public_statistics_cli.php b/tools/public_statistics_cli.php index 885ccfc8..1b6faf27 100644 --- a/tools/public_statistics_cli.php +++ b/tools/public_statistics_cli.php @@ -56,7 +56,7 @@ function statpage($board = false, $boards, $stat_file) { 'mod' => false, 'hide_dashboard_link' => true, 'title' => _("Statistics") . ($board?" for /" . $board . "/":""), - 'subtitle' => _("Last Updated : ") . gmstrftime($config['public_stats']['date']), + 'subtitle' => _("Last Updated : ") . '', 'nojavascript' => true, 'boardlist' => createBoardlist(false), 'body' => Element('mod/statistics.html', array(