Skip to content

Commit

Permalink
Add DTSTAMP to ICS generator, also use UTC timestamps instead of defi…
Browse files Browse the repository at this point in the history
…ning timezone
  • Loading branch information
kodie authored and wxactly committed Feb 28, 2023
1 parent 40b29c7 commit c2eb4d3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Generators/Ics.php
Original file line number Diff line number Diff line change
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 = 'e:Ymd\THis';
protected $dateTimeFormat = 'Ymd\THis';

/** @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;TZID='.$link->from->format($dateTimeFormat);
$url[] = 'DTSTART:'.$link->from->format($dateTimeFormat);
$url[] = 'DTSTAMP:'.gmdate($dateTimeFormat, $link->from->getTimestamp()).'Z';
$url[] = 'DTSTART:'.gmdate($dateTimeFormat, $link->from->getTimestamp()).'Z';
$url[] = 'DURATION:P'.(max(1, $link->from->diff($link->to)->days)).'D';
} else {
$url[] = 'DTSTAMP;TZID='.$link->from->format($dateTimeFormat);
$url[] = 'DTSTART;TZID='.$link->from->format($dateTimeFormat);
$url[] = 'DTEND;TZID='.$link->to->format($dateTimeFormat);
$url[] = 'DTSTAMP:'.gmdate($dateTimeFormat, $link->from->getTimestamp()).'Z';
$url[] = 'DTSTART:'.gmdate($dateTimeFormat, $link->from->getTimestamp()).'Z';
$url[] = 'DTEND:'.gmdate($dateTimeFormat, $link->to->getTimestamp()).'Z';
}

if ($link->description) {
Expand Down

0 comments on commit c2eb4d3

Please sign in to comment.