From e994ae908634a69ee29a1af63ce0b277d8634b7a Mon Sep 17 00:00:00 2001 From: Markus Poerschke Date: Mon, 5 Jul 2021 22:21:25 +0200 Subject: [PATCH 1/2] Add LAST-MODIFIED property --- src/Domain/Entity/Event.php | 18 ++++++++++++++++++ src/Presentation/Factory/EventFactory.php | 4 ++++ .../Presentation/Factory/EventFactoryTest.php | 14 +++++++++++++- website/docs/maturity-matrix.md | 2 +- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Domain/Entity/Event.php b/src/Domain/Entity/Event.php index 220d4501..13a1f835 100644 --- a/src/Domain/Entity/Event.php +++ b/src/Domain/Entity/Event.php @@ -28,6 +28,7 @@ class Event private ?Occurrence $occurrence = null; private ?Location $location = null; private ?Organizer $organizer = null; + private ?Timestamp $lastModified = null; /** * @var array @@ -200,4 +201,21 @@ public function getAttachments(): array { return $this->attachments; } + + public function getLastModified(): Timestamp + { + return $this->lastModified; + } + + public function hasLastModified(): bool + { + return $this->lastModified !== null; + } + + public function setLastModified(?Timestamp $lastModified): self + { + $this->lastModified = $lastModified; + + return $this; + } } diff --git a/src/Presentation/Factory/EventFactory.php b/src/Presentation/Factory/EventFactory.php index bf2039ef..fb289e5d 100644 --- a/src/Presentation/Factory/EventFactory.php +++ b/src/Presentation/Factory/EventFactory.php @@ -76,6 +76,10 @@ protected function getProperties(Event $event): Generator yield new Property('UID', new TextValue((string) $event->getUniqueIdentifier())); yield new Property('DTSTAMP', new DateTimeValue($event->getTouchedAt())); + if ($event->hasLastModified()) { + yield new Property('LAST-MODIFIED', new DateTimeValue($event->getLastModified())); + } + if ($event->hasSummary()) { yield new Property('SUMMARY', new TextValue($event->getSummary())); } diff --git a/tests/Unit/Presentation/Factory/EventFactoryTest.php b/tests/Unit/Presentation/Factory/EventFactoryTest.php index 14946ca3..4226afdf 100644 --- a/tests/Unit/Presentation/Factory/EventFactoryTest.php +++ b/tests/Unit/Presentation/Factory/EventFactoryTest.php @@ -44,12 +44,24 @@ public function testMinimalEvent() ) ); - $event = (new Event(new UniqueIdentifier('event1')))->touch($currentTime); + $lastModified = new Timestamp( + DateTimeImmutable::createFromFormat( + 'Y-m-d H:i:s', + '2019-10-09 10:11:22', + new DateTimeZone('UTC') + ) + ); + + $event = (new Event(new UniqueIdentifier('event1'))) + ->touch($currentTime) + ->setLastModified($lastModified) + ; $expected = implode(ContentLine::LINE_SEPARATOR, [ 'BEGIN:VEVENT', 'UID:event1', 'DTSTAMP:20191110T112233Z', + 'LAST-MODIFIED:20191009T101122Z', 'END:VEVENT', '', ]); diff --git a/website/docs/maturity-matrix.md b/website/docs/maturity-matrix.md index 65efd05e..8bc58c3f 100644 --- a/website/docs/maturity-matrix.md +++ b/website/docs/maturity-matrix.md @@ -42,7 +42,7 @@ See [RFC 5545 section 3.6.1](https://tools.ietf.org/html/rfc5545#section-3.6.1). | created | ✖ | | description | ✔ | | geo | ✔ | -| last-mod | ✖ | +| last-mod | ✔ | | location | ✔ | | organizer | ✔ | | priority | ✖ | From ba57710677ed32972ec9c4e394ab4379be977fec Mon Sep 17 00:00:00 2001 From: Markus Poerschke Date: Mon, 5 Jul 2021 22:26:14 +0200 Subject: [PATCH 2/2] Add LAST-MODIFIED property --- CHANGELOG.md | 4 ++++ src/Domain/Entity/Event.php | 2 ++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c08454b..7a062c32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Event LAST-MODIFIED property [#298](https://github.com/markuspoerschke/iCal/pull/298) + ## [2.2.0] - 2021-05-03 ### Added diff --git a/src/Domain/Entity/Event.php b/src/Domain/Entity/Event.php index 13a1f835..036220c3 100644 --- a/src/Domain/Entity/Event.php +++ b/src/Domain/Entity/Event.php @@ -204,6 +204,8 @@ public function getAttachments(): array public function getLastModified(): Timestamp { + assert($this->lastModified !== null); + return $this->lastModified; }