From ad76a90850fe56eb95dbe5c153b41ed5fc18bdf1 Mon Sep 17 00:00:00 2001 From: Christopher Teutsch Date: Fri, 21 Feb 2020 22:22:22 +0100 Subject: [PATCH] rearrange event formatting into function --- index.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/index.php b/index.php index 3d12998..e773ed0 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,7 @@ (object) array( 'state_string' => 'Das Dorf ist gerade geschlossen.', @@ -64,6 +64,18 @@ if ($locale !== null){ setlocale(LC_TIME, $locale); } $v = file_get_contents('/media/sg/dorf.jetzt_visitors'); +function format_event($event): string{ + global $DATE_FORMAT, $ical; + $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'); + } + return $startdate_str . ' – ' . $enddate_str; +} ?> @@ -96,23 +108,14 @@ $v = file_get_contents('/media/sg/dorf.jetzt_visitors');
Nächste Veranstaltung

summary, ENT_QUOTES, 'UTF-8') ?>
- iCalDateToDateTime($first_event->dtstart_array[3])->format($DATE_FORMAT) ?> +

Danach:
- +
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 . ' – ' . $enddate_str); ?> summary) ?>