You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
990 B
30 lines
990 B
<?php |
|
// read vor.txt and generate vor.md, inserting dates if missing |
|
date_default_timezone_set("CET"); |
|
setlocale(LC_TIME, 'de_DE.utf8'); |
|
$file_txt = 'vor.txt'; |
|
$file_md = 'vor.md'; |
|
$fil = file($file_txt, FILE_IGNORE_NEW_LINES); |
|
// Insert header |
|
$arr = ['| | | |', '|:------|:------|:------|']; |
|
$ts=(new DateTime('first day of this month'))->getTimeStamp(); |
|
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); |
|
} |
|
$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); |
|
?>
|
|
|