From ac009565f5205400ec294284d5f5d440ada24a7c Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Thu, 13 Jun 2024 14:40:58 +0200 Subject: [PATCH] Fix #134 --- src/Components/Event.php | 2 +- src/Properties/DateTimeProperty.php | 5 ++++- tests/ComponentPayloadTest.php | 4 ++++ tests/Components/CalendarTest.php | 18 +++++++++--------- ...rationTest__it_can_create_a_calendar__1.txt | 6 +++--- ...t__it_can_write_out_a_timezone_entry__1.txt | 2 +- ...oneTest__it_can_write_out_a_timezone__1.txt | 2 +- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/Components/Event.php b/src/Components/Event.php index 84600b8..9effc9b 100644 --- a/src/Components/Event.php +++ b/src/Components/Event.php @@ -427,7 +427,7 @@ private function resolveProperties(ComponentPayload $payload): self { $payload ->property(TextProperty::create('UID', $this->uuid)) - ->property(DateTimeProperty::create('DTSTAMP', $this->created, $this->withoutTimezone)) + ->property(DateTimeProperty::create('DTSTAMP', $this->created)) ->optional( $this->name, fn () => TextProperty::create('SUMMARY', $this->name) diff --git a/src/Properties/DateTimeProperty.php b/src/Properties/DateTimeProperty.php index ff152ae..6740eb2 100644 --- a/src/Properties/DateTimeProperty.php +++ b/src/Properties/DateTimeProperty.php @@ -12,6 +12,8 @@ class DateTimeProperty extends Property private DateTimeZone $dateTimeZone; + private bool $withoutTimeZone; + public static function fromDateTime( string $name, DateTimeInterface $dateTime, @@ -37,6 +39,7 @@ private function __construct( $this->name = $name; $this->dateTimeValue = $dateTimeValue; $this->dateTimeZone = $dateTimeValue->getDateTime()->getTimezone(); + $this->withoutTimeZone = $withoutTimeZone; if (! $withoutTimeZone && ! $this->isUTC()) { $this->addParameter(new Parameter('TZID', $this->dateTimeZone->getName())); @@ -49,7 +52,7 @@ private function __construct( public function getValue(): string { - return $this->isUTC() && $this->dateTimeValue->hasTime() + return $this->isUTC() && $this->dateTimeValue->hasTime() && $this->withoutTimeZone === false ? "{$this->dateTimeValue->format()}Z" : $this->dateTimeValue->format(); } diff --git a/tests/ComponentPayloadTest.php b/tests/ComponentPayloadTest.php index 5ec0ac9..ba448c4 100644 --- a/tests/ComponentPayloadTest.php +++ b/tests/ComponentPayloadTest.php @@ -3,7 +3,11 @@ namespace Spatie\IcalendarGenerator\Tests; use DateTime; +use DateTimeImmutable; +use DateTimeZone; use Exception; +use Spatie\IcalendarGenerator\Components\Calendar; +use Spatie\IcalendarGenerator\Components\Event; use function PHPUnit\Framework\assertEquals; use Spatie\IcalendarGenerator\ComponentPayload; use Spatie\IcalendarGenerator\Properties\DateTimeProperty; diff --git a/tests/Components/CalendarTest.php b/tests/Components/CalendarTest.php index a29b5e0..a8bcf00 100644 --- a/tests/Components/CalendarTest.php +++ b/tests/Components/CalendarTest.php @@ -237,7 +237,7 @@ function (Event $event) { BEGIN:VTIMEZONE\r TZID:UTC\r BEGIN:STANDARD\r -DTSTART:20180406T000000Z\r +DTSTART:20180406T000000\r TZOFFSETFROM:+0000\r TZOFFSETTO:+0000\r END:STANDARD\r @@ -252,22 +252,22 @@ function (Event $event) { BEGIN:VTIMEZONE\r TZID:Europe/Brussels\r BEGIN:STANDARD\r -DTSTART:20191027T030000Z\r +DTSTART:20191027T030000\r TZOFFSETFROM:+0200\r TZOFFSETTO:+0100\r END:STANDARD\r BEGIN:DAYLIGHT\r -DTSTART:20200329T020000Z\r +DTSTART:20200329T020000\r TZOFFSETFROM:+0100\r TZOFFSETTO:+0200\r END:DAYLIGHT\r BEGIN:STANDARD\r -DTSTART:20201025T030000Z\r +DTSTART:20201025T030000\r TZOFFSETFROM:+0200\r TZOFFSETTO:+0100\r END:STANDARD\r BEGIN:DAYLIGHT\r -DTSTART:20210328T020000Z\r +DTSTART:20210328T020000\r TZOFFSETFROM:+0100\r TZOFFSETTO:+0200\r END:DAYLIGHT\r @@ -282,22 +282,22 @@ function (Event $event) { BEGIN:VTIMEZONE\r TZID:America/New_York\r BEGIN:STANDARD\r -DTSTART:20191103T020000Z\r +DTSTART:20191103T020000\r TZOFFSETFROM:-0400\r TZOFFSETTO:-0500\r END:STANDARD\r BEGIN:DAYLIGHT\r -DTSTART:20200308T020000Z\r +DTSTART:20200308T020000\r TZOFFSETFROM:-0500\r TZOFFSETTO:-0400\r END:DAYLIGHT\r BEGIN:STANDARD\r -DTSTART:20201101T020000Z\r +DTSTART:20201101T020000\r TZOFFSETFROM:-0400\r TZOFFSETTO:-0500\r END:STANDARD\r BEGIN:DAYLIGHT\r -DTSTART:20210314T020000Z\r +DTSTART:20210314T020000\r TZOFFSETFROM:-0500\r TZOFFSETTO:-0400\r END:DAYLIGHT\r diff --git a/tests/__snapshots__/IntegrationTest__it_can_create_a_calendar__1.txt b/tests/__snapshots__/IntegrationTest__it_can_create_a_calendar__1.txt index 38a3ed8..429bfa3 100644 --- a/tests/__snapshots__/IntegrationTest__it_can_create_a_calendar__1.txt +++ b/tests/__snapshots__/IntegrationTest__it_can_create_a_calendar__1.txt @@ -8,7 +8,7 @@ X-PUBLISHED-TTL:PT5M BEGIN:VTIMEZONE TZID:UTC BEGIN:STANDARD -DTSTART:20180609T150000Z +DTSTART:20180609T150000 TZOFFSETFROM:+0000 TZOFFSETTO:+0000 END:STANDARD @@ -16,12 +16,12 @@ END:VTIMEZONE BEGIN:VTIMEZONE TZID:Europe/Brussels BEGIN:STANDARD -DTSTART:20181028T030000Z +DTSTART:20181028T030000 TZOFFSETFROM:+0200 TZOFFSETTO:+0100 END:STANDARD BEGIN:DAYLIGHT -DTSTART:20190331T020000Z +DTSTART:20190331T020000 TZOFFSETFROM:+0100 TZOFFSETTO:+0200 END:DAYLIGHT diff --git a/tests/__snapshots__/TimezoneEntryTest__it_can_write_out_a_timezone_entry__1.txt b/tests/__snapshots__/TimezoneEntryTest__it_can_write_out_a_timezone_entry__1.txt index 9c22f0d..d30bcb2 100644 --- a/tests/__snapshots__/TimezoneEntryTest__it_can_write_out_a_timezone_entry__1.txt +++ b/tests/__snapshots__/TimezoneEntryTest__it_can_write_out_a_timezone_entry__1.txt @@ -1,5 +1,5 @@ BEGIN:DAYLIGHT -DTSTART:20200516T120000Z +DTSTART:20200516T120000 TZOFFSETFROM:+00:00 TZOFFSETTO:+02:00 TZNAME:Europe - Brussels diff --git a/tests/__snapshots__/TimezoneTest__it_can_write_out_a_timezone__1.txt b/tests/__snapshots__/TimezoneTest__it_can_write_out_a_timezone__1.txt index c4eede0..2f7e1ea 100644 --- a/tests/__snapshots__/TimezoneTest__it_can_write_out_a_timezone__1.txt +++ b/tests/__snapshots__/TimezoneTest__it_can_write_out_a_timezone__1.txt @@ -3,7 +3,7 @@ TZID:Europe/Brussels TZURL:https://spatie.be LAST-MODIFIED:20200516T100000Z BEGIN:STANDARD -DTSTART:20200516T120000Z +DTSTART:20200516T120000 TZOFFSETFROM:+00:00 TZOFFSETTO:+02:00 END:STANDARD