replace next meeting days with php script. no more manual adjusting needed

This commit is contained in:
Nils 2023-10-17 21:08:21 +02:00
parent b11ebef267
commit d37b031139
2 changed files with 69 additions and 14 deletions

View File

@ -1,3 +1,9 @@
<?php
include "third_wednesday.php";
$nextDate = nextThirdWednesday();
$followingDates = listNextElevenThirdWendesdays();
?>
<!doctype html>
<html lang="en">
<head>
@ -175,21 +181,10 @@
<div class="Information">
<h4>Termine<span><a href="https://plan.osamc.de">18.10.2023</a> 19:00 Uhr </span></h4>
<h4>Termine<span><a href="https://plan.osamc.de"><?php echo $nextDate; ?></a> 19:00 Uhr </span></h4>
<p>Jeder Dritte Mittwoch im Monat (außer Dezember):<br>
15.11.
17.1.
21.2.
20.3.
17.4.
15.5.
19.6.
17.7.
21.8.
18.9.
16.10.
20.11.
<?php echo $followingDates; ?>
</p>
</div>
@ -231,7 +226,7 @@
<div class="Form">
<h3>Nächstes Treffen: <span>18.10.2023</span></h3>
<h3>Nächstes Treffen: <span><?php echo $nextDate; ?></span></h3>
<form method="post" action="#">
<fieldset disabled>

60
third_wednesday.php Normal file
View File

@ -0,0 +1,60 @@
<?php
function nextThirdWednesday() {
// Set the default time zone to your desired one
date_default_timezone_set('Europe/Berlin');
$date = new DateTime( 'third wednesday of this month, 17:00' );
if( date_create()->diff( $date )->invert )
{
$date = new DateTime( 'third wednesday of next month, 17:00' );
}
if ($date->format('m') == '12') {
// If it's December, advance to January of the following year
$date->modify('third wednesday of January next year');
$date->modify('-1 day'); // not sure why.
}
$nextThirdWednesdayFormatted = $date->format('d.m.y');
return $nextThirdWednesdayFormatted;
}
function listNextElevenThirdWendesdays() {
date_default_timezone_set('Europe/Berlin');
//Start with the actual next meeting date, that is already calculated by another function already.
$date = new DateTime( 'third wednesday of this month, 17:00' );
if( date_create()->diff( $date )->invert )
{
$date = new DateTime( 'third wednesday of next month, 17:00' );
}
if ($date->format('m') == '12') {
// If it's December, advance to January of the following year
$date->modify('third wednesday of January next year');
$date->modify('-1 day'); // not sure why.
}
$result = "";
for ($i=0; $i < 11; $i++) {
$date->modify('third wednesday of next month');
//Again:
if ($date->format('m') == '12') {
// If it's December, advance to January of the following year
$date->modify('third wednesday of January next year');
$date->modify('-1 day'); // not sure why.
}
$result = $result . " " . $date->format('d.m');
}
return $result;
}
?>