Parse event durations

This commit is contained in:
Christopher Teutsch 2020-02-21 21:52:27 +01:00
parent 2130199951
commit b452d54dd3
Signed by: iwonder
GPG Key ID: 0EE33D788D50130D

View File

@ -1,6 +1,7 @@
<?php
require_once 'vendor/autoload.php';
use ICal\ICal;
$DATE_FORMAT = 'd.m.Y H:i';
$state_map = array(
'closed' => (object) array(
'state_string' => 'Das Dorf ist gerade <em>geschlossen</em>.',
@ -80,9 +81,7 @@ $v = file_get_contents('/media/sg/dorf.jetzt_visitors');
<div class="card mb-3 text-center">
<div class="card-body">
<h5 class="card-title">Türstatus</h5>
<i class="material-icons" id="state-icn" style="color:<?= $state_map[$state]->color ?>;font-size:16rem;">
<?= $state_map[$state]->svg ?>
</i>
<i class="material-icons" id="state-icn" style="color:<?= $state_map[$state]->color ?>;font-size:16rem;"><?= $state_map[$state]->svg ?></i>
<p class="card-text"><?= $state_map[$state]->state_string ?></p>
<div class="btn-wrapper">
<a href="https://wiki.chaosdorf.de/Raumstatus" class="btn btn-lg btn-block btn-primary">What's this?</a>
@ -96,14 +95,23 @@ $v = file_get_contents('/media/sg/dorf.jetzt_visitors');
<h6 class="card-subtitle mb-2 text-muted">Nächste Veranstaltung</h6>
<p class="card-text">
<h5 class="font-weight-bold"><?= htmlspecialchars($first_event->summary, ENT_QUOTES, 'UTF-8') ?></h5>
<span class="font-weight-normal"><?= $ical->iCalDateToDateTime($first_event->dtstart_array[3])->format('Y-m-d H:i'); ?></span>
<span class="font-weight-normal"><?= $ical->iCalDateToDateTime($first_event->dtstart_array[3])->format($DATE_FORMAT) ?></span>
</p>
<h5 class="card-title">Danach:</h5>
<table class="table">
<tbody>
<?php foreach ($events as $event) : ?>
<tr>
<th scope="row"><?= $ical->iCalDateToDateTime($event->dtstart_array[3])->format('Y-m-d H:i') ?></th>
<th scope="row"><?php
$startdate_loop = $ical->iCalDateToDateTime($event->dtstart_array[3]);
$startdate_str = $startdate_loop->format($DATE_FORMAT);
$interval_loop = new DateInterval($event->duration);
if ($interval_loop->d != 0 || $interval_loop->h >= 24){
$enddate_str = $startdate_loop->add($interval_loop)->format($DATE_FORMAT);
}else{
$enddate_str = $startdate_loop->add($interval_loop)->format('H:i');
}
echo($startdate_str . ' &mdash; ' . $enddate_str); ?></th>
<td><?= htmlspecialchars($event->summary) ?></td>
</tr>
<?php endforeach ?>