From b48d3d55798dbdc87eae3a84095a0bd4e25c9e16 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 26 Oct 2022 15:47:43 +0200 Subject: [PATCH] gen_vor.php --- gen_vor.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 gen_vor.php diff --git a/gen_vor.php b/gen_vor.php new file mode 100644 index 0000000..f2d17b3 --- /dev/null +++ b/gen_vor.php @@ -0,0 +1,44 @@ +getTimeStamp(); +$tues_ts = strtotime('fourth tuesday of this month', $ts); + +// Are we past the fourth Tuesday of the month? +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) { + // 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 . '|'); + } +} +file_put_contents($file_md, implode(PHP_EOL, $arr) . PHP_EOL); +?> \ No newline at end of file