From dd6af287f3b58b59bfd1f4a8fa05d93fb94727e0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20G=C3=BCnther?=
Date: Sat, 2 Mar 2024 18:13:44 +0100
Subject: [PATCH] Bugfix timezone on events
---
lib/ics-parser/Event.php | 19 ++++++++-----------
lib/ics-parser/ICal.php | 1 -
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/lib/ics-parser/Event.php b/lib/ics-parser/Event.php
index f3aa776..cd2f5c8 100644
--- a/lib/ics-parser/Event.php
+++ b/lib/ics-parser/Event.php
@@ -154,21 +154,20 @@ class Event
{
foreach ($data as $key => $value) {
if ($key == 'DTSTART_array' || $key == 'DTEND_array') {
+ $timeZone = 'Europe/Berlin';
+ if (isset($value[0]['TZID'])) {
+ $timeZone = $value[0]['TZID'];
+ }
$dateString = $value[1];
- $dateTime = \DateTime::createFromFormat('Ymd\THis', $dateString);
+
+ $dateTime = \DateTime::createFromFormat('Ymd\THis', $dateString, new \DateTimeZone($timeZone));
if (false === $dateTime) {
$this->wholeDay = true;
- $dateTime = \DateTime::createFromFormat('Ymd', $dateString);
+ $dateTime = \DateTime::createFromFormat('Ymd', $dateString, new \DateTimeZone($timeZone));
}
- $timeZone = 'Europe/Berlin';
- if (isset($value[0]['TZID'])) {
- $timeZone = $value[0]['TZID'];
- }
-
- $dateTime->setTimezone(new \DateTimeZone($timeZone));
-
+ $dateTime->setTimezone(new \DateTimeZone('UTC'));
if ($key == 'DTSTART_array') {
$this->start = $dateTime->format('d.m.Y H:i:s');
$this->startInt = $dateTime->getTimestamp();
@@ -176,9 +175,7 @@ class Event
$this->end = $dateTime->format('d.m.Y H:i:s');
$this->endInt = $dateTime->getTimestamp();
}
-
} else {
-
$variable = self::snakeCase($key);
if (property_exists($this, $variable)) {
$this->{$variable} = $this->prepareData($value);
diff --git a/lib/ics-parser/ICal.php b/lib/ics-parser/ICal.php
index f88e4f8..b7fbc37 100644
--- a/lib/ics-parser/ICal.php
+++ b/lib/ics-parser/ICal.php
@@ -2223,7 +2223,6 @@ class ICal
if ($ignoreUtc && strtoupper($timeZone) === self::TIME_ZONE_UTC) {
return null;
}
-
return $timeZone;
}