Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LAST-MODIFIED property #298

Merged
merged 2 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/Domain/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Event
private ?Occurrence $occurrence = null;
private ?Location $location = null;
private ?Organizer $organizer = null;
private ?Timestamp $lastModified = null;

/**
* @var array<Alarm>
Expand Down Expand Up @@ -200,4 +201,23 @@ public function getAttachments(): array
{
return $this->attachments;
}

public function getLastModified(): Timestamp
{
assert($this->lastModified !== null);

return $this->lastModified;
}

public function hasLastModified(): bool
{
return $this->lastModified !== null;
}

public function setLastModified(?Timestamp $lastModified): self
{
$this->lastModified = $lastModified;

return $this;
}
}
4 changes: 4 additions & 0 deletions src/Presentation/Factory/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
14 changes: 13 additions & 1 deletion tests/Unit/Presentation/Factory/EventFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'',
]);
Expand Down
2 changes: 1 addition & 1 deletion website/docs/maturity-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | ✖ |
Expand Down