From fc4364722d822ecad9c6d001b5c9858c7ef4e057 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 26 Oct 2022 15:01:34 +0200 Subject: [PATCH] Prepped gen_vor.php for PHP 8.1 --- gen_vor.php | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/gen_vor.php b/gen_vor.php index ea2a230..631f47a 100644 --- a/gen_vor.php +++ b/gen_vor.php @@ -15,23 +15,30 @@ if ((new DateTime())->getTimeStamp() >= $tues_ts) { $ts = strtotime('+1 month', $ts); } +// This for PHP >= 8.1 as the old strftime will be deprecated by then +// $date_time = new DateTime(); +// $date_time->setTimestamp(strtotime('fourth tuesday of this month', $ts)); foreach ($fil as $line) { - $fields = array_filter(explode('|', $line)); - if (count($fields) == 2) { - // Date missing, insert - $tuesday = strftime('%A, %d.%m.%Y ', strtotime('fourth tuesday of this month', $ts)); - array_unshift($fields, $tuesday); + // Skip empty lines + if (strlen($line)) { + $fields = array_filter(explode('|', $line)); + if (count($fields) == 2) { + // Date missing, insert + $tuesday = strftime('%A, %d.%m.%Y ', strtotime('fourth tuesday of this month', $ts)); + // $tuesday = datefmt_format_object($date_time, 'cccc, d.M.yyyy ', 'de_DE.utf8'); + array_unshift($fields, $tuesday); + } + $ts = strtotime('+1 month', $ts); + $li = implode('|', $fields); + // Insert leading and trailing spaces if required + if ($li[0] != ' ') { + $li = ' ' . $li; + } + if (substr($li, -1) != ' ') { + $li = $li . ' '; + } + array_push($arr, '|' . $li . '|'); } - $ts = strtotime('+1 month', $ts); - $li = implode('|', $fields); - // Insert leading and trailing spaces if required - if ($li[0] != ' ') { - $li = ' ' . $li; - } - if (substr($li, -1) != ' ') { - $li = $li . ' '; - } - array_push($arr, '|' . $li . '|'); } file_put_contents($file_md, implode(PHP_EOL, $arr) . PHP_EOL); ?>