Skip to content

Commit

Permalink
fix: ics as file
Browse files Browse the repository at this point in the history
  • Loading branch information
atymic committed May 24, 2023
1 parent a74d683 commit feb566d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Generators/Ics.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
class Ics implements Generator
{
public const OPTION_AS_FILE = 'as_file';

/** @var string {@see https://www.php.net/manual/en/function.date.php} */
protected $dateFormat = 'Ymd';
/** @var string */
Expand Down Expand Up @@ -64,6 +66,10 @@ public function generate(Link $link): string
$url[] = 'END:VEVENT';
$url[] = 'END:VCALENDAR';

if ($this->options[self::OPTION_AS_FILE] ?? false) {
return implode("\r\n", $url);
}

return $this->buildLink($url);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Generators/IcsGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ public function it_has_a_product_dtstamp(): void
$this->generator(['DTSTAMP' => '20180201T090000Z'])->generate($this->createShortEventLink())
);
}

/** @test */
public function it_can_generate_a_file(): void
{
$this->assertMatchesSnapshot(
$this->generator([Ics::OPTION_AS_FILE => true])->generate($this->createShortEventLink())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:Spatie calendar-links
BEGIN:VEVENT
UID:94ab75add84a67c019eae57539658036
SUMMARY:Birthday
DTSTAMP:20180201T090000Z
DTSTART:20180201T090000Z
DTEND:20180201T180000Z
DESCRIPTION:With balloons\, clowns and stuff\nBring a dog\, bring a frog
LOCATION:Party Lane 1A\, 1337 Funtown
END:VEVENT
END:VCALENDAR

0 comments on commit feb566d

Please sign in to comment.