Skip to content

Commit

Permalink
Fix #134
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Jun 13, 2024
1 parent 8e87f6b commit ac00956
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Components/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/Properties/DateTimeProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class DateTimeProperty extends Property

private DateTimeZone $dateTimeZone;

private bool $withoutTimeZone;

public static function fromDateTime(
string $name,
DateTimeInterface $dateTime,
Expand All @@ -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()));
Expand All @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions tests/ComponentPayloadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions tests/Components/CalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ X-PUBLISHED-TTL:PT5M
BEGIN:VTIMEZONE
TZID:UTC
BEGIN:STANDARD
DTSTART:20180609T150000Z
DTSTART:20180609T150000
TZOFFSETFROM:+0000
TZOFFSETTO:+0000
END:STANDARD
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BEGIN:DAYLIGHT
DTSTART:20200516T120000Z
DTSTART:20200516T120000
TZOFFSETFROM:+00:00
TZOFFSETTO:+02:00
TZNAME:Europe - Brussels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ac00956

Please sign in to comment.