diff options
author | Arno Richter <oelna@oelna.de> | 2022-12-09 14:41:22 +0100 |
---|---|---|
committer | Arno Richter <oelna@oelna.de> | 2022-12-09 14:53:20 +0100 |
commit | 7d3ce1014a33d621f20f008b1cf6bc1357c651dc (patch) | |
tree | c72a7803eb3cb54a27db8388c6b59b1bb505eba3 | |
parent | 85584d7035b20373238fa87b96b92abc3be43d1f (diff) | |
download | microblog-7d3ce1014a33d621f20f008b1cf6bc1357c651dc.tar.gz microblog-7d3ce1014a33d621f20f008b1cf6bc1357c651dc.tar.bz2 microblog-7d3ce1014a33d621f20f008b1cf6bc1357c651dc.zip |
updated date handling for PHP 8
-rw-r--r-- | functions.php | 10 | ||||
-rw-r--r-- | single.inc.php | 7 | ||||
-rw-r--r-- | timeline.inc.php | 7 |
3 files changed, 16 insertions, 8 deletions
diff --git a/functions.php b/functions.php index 7041b26..eb62c2f 100644 --- a/functions.php +++ b/functions.php @@ -99,20 +99,22 @@ function rebuild_feed($amount=10) { 'items' => array() ); - // make a timezone string for dates (is this dumb?) - $timezone_offset = timezone_offset_get(timezone_open('UTC'), new DateTime())/60/60; // this is probably incorrect - $timezone_offset_string = (is_int($timezone_offset) && $timezone_offset >= 0) ? '+'.str_pad($timezone_offset, 2, '0', STR_PAD_LEFT).':00' : '-'.str_pad($timezone_offset, 2, '0', STR_PAD_LEFT).':00'; + // make a timezone string for dates + $timezone_offset_string = '+00:00'; // because unix timestamps are always GMT? $posts = db_select_posts(NOW+60, $amount, 'desc'); foreach($posts as $post) { + $date = date_create(); + date_timestamp_set($date, $post['post_timestamp']); + $feed['items'][] = array( 'id' => $config['url'].'/'.$post['id'], 'url' => $config['url'].'/'.$post['id'], 'title' => '', 'content_html' => $post['post_content'], - 'date_published' => strftime('%Y-%m-%dT%H:%M:%S', $post['post_timestamp']).$timezone_offset_string + 'date_published' => date_format($date, 'Y-m-d\TH:i:s').$timezone_offset_string ); } diff --git a/single.inc.php b/single.inc.php index dfcb7e3..7eac8fb 100644 --- a/single.inc.php +++ b/single.inc.php @@ -22,8 +22,11 @@ </nav> <?php if(!empty($post)): ?> <?php - $datetime = strftime('%Y-%m-%d %H:%M:%S', $post['post_timestamp']); - $formatted_time = strftime('%b %d %Y %H:%M', $post['post_timestamp']); + $date = date_create(); + date_timestamp_set($date, $post['post_timestamp']); + + $datetime = date_format($date, 'Y-m-d H:i:s'); + $formatted_time = date_format($date, 'M d Y H:i'); ?> <time class="post-timestamp" datetime="<?= $datetime ?>" data-unix-time="<?= $post['post_timestamp'] ?>"><?= $formatted_time ?></time> <p class="post-content"><?= nl2br(autolink($post['post_content'])) ?></p> diff --git a/timeline.inc.php b/timeline.inc.php index 76185bc..bfe3d70 100644 --- a/timeline.inc.php +++ b/timeline.inc.php @@ -38,8 +38,11 @@ <?php foreach($posts as $post): ?> <li data-post-id="<?= $post['id'] ?>"> <?php - $datetime = strftime('%Y-%m-%d %H:%M:%S', $post['post_timestamp']); - $formatted_time = strftime('%b %d %Y %H:%M', $post['post_timestamp']); + $date = date_create(); + date_timestamp_set($date, $post['post_timestamp']); + + $datetime = date_format($date, 'Y-m-d H:i:s'); + $formatted_time = date_format($date, 'M d Y H:i'); ?> <a class="post-timestamp" href="<?= $config['url'] ?>/<?= $post['id'] ?>"><time datetime="<?= $datetime ?>" data-unix-time="<?= $post['post_timestamp'] ?>"><?= $formatted_time ?></time></a> <p class="post-content"><?= nl2br(autolink($post['post_content'])) ?></p> |