Skip to content

Commit

Permalink
Merge pull request #167 from thinkshout/fix-ics-generator
Browse files Browse the repository at this point in the history
Update datetime format to include Z, remove Z from all-day dates
  • Loading branch information
lptn committed Mar 1, 2023
2 parents aecd642 + f39f6ce commit fb10053
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/Generators/Ics.php
Expand Up @@ -13,7 +13,7 @@ class Ics implements Generator
/** @var string {@see https://www.php.net/manual/en/function.date.php} */
protected $dateFormat = 'Ymd';
/** @var string */
protected $dateTimeFormat = 'Ymd\THis';
protected $dateTimeFormat = 'Ymd\THis\Z';

/** @var array<non-empty-string, non-empty-string> */
protected $options = [];
Expand Down Expand Up @@ -41,13 +41,13 @@ public function generate(Link $link): string
$dateTimeFormat = $link->allDay ? $this->dateFormat : $this->dateTimeFormat;

if ($link->allDay) {
$url[] = 'DTSTAMP:'.gmdate($dateTimeFormat, $link->from->getTimestamp()).'Z';
$url[] = 'DTSTART:'.gmdate($dateTimeFormat, $link->from->getTimestamp()).'Z';
$url[] = 'DTSTAMP:'.gmdate($dateTimeFormat, $link->from->getTimestamp());
$url[] = 'DTSTART:'.gmdate($dateTimeFormat, $link->from->getTimestamp());
$url[] = 'DURATION:P'.(max(1, $link->from->diff($link->to)->days)).'D';
} else {
$url[] = 'DTSTAMP:'.gmdate($dateTimeFormat, $link->from->getTimestamp()).'Z';
$url[] = 'DTSTART:'.gmdate($dateTimeFormat, $link->from->getTimestamp()).'Z';
$url[] = 'DTEND:'.gmdate($dateTimeFormat, $link->to->getTimestamp()).'Z';
$url[] = 'DTSTAMP:'.gmdate($dateTimeFormat, $link->from->getTimestamp());
$url[] = 'DTSTART:'.gmdate($dateTimeFormat, $link->from->getTimestamp());
$url[] = 'DTEND:'.gmdate($dateTimeFormat, $link->to->getTimestamp());
}

if ($link->description) {
Expand Down
Expand Up @@ -4,8 +4,8 @@ PRODID:Spatie calendar-links
BEGIN:VEVENT
UID:47e044bc36ced4538c62fc17c3ba087b
SUMMARY:Birthday
DTSTAMP:20180201Z
DTSTART:20180201Z
DTSTAMP:20180201
DTSTART:20180201
DURATION:P5D
DESCRIPTION:With balloons\, clowns and stuff\nBring a dog\, bring a frog
LOCATION:Party Lane 1A\, 1337 Funtown
Expand Down
Expand Up @@ -4,8 +4,8 @@ PRODID:Spatie calendar-links
BEGIN:VEVENT
UID:aaf6b0d9a2c43d4a1c803a8c80793a08
SUMMARY:Birthday
DTSTAMP:20180201Z
DTSTART:20180201Z
DTSTAMP:20180201
DTSTART:20180201
DURATION:P1D
DESCRIPTION:With balloons\, clowns and stuff\nBring a dog\, bring a frog
LOCATION:Party Lane 1A\, 1337 Funtown
Expand Down

0 comments on commit fb10053

Please sign in to comment.