Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active January 13, 2024 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vielhuber/70de341d1c86972d80f83123c7072fb1 to your computer and use it in GitHub Desktop.
Save vielhuber/70de341d1c86972d80f83123c7072fb1 to your computer and use it in GitHub Desktop.
ical ics download #php
// composer require eluceo/ical
require_once(__DIR__ . '/vendor/autoload.php');
$date_begin = '2023-01-01 20:00:00';
$date_end = '2023-01-01 21:00:00';
$d = new \DateTime($date_end, new \DateTimeZone('Europe/Berlin'));
$d->setTimeZone(new \DateTimeZone('UTC'));
$date_begin = $d->format('Y-m-d H:i:s');
$d = new \DateTime($date_end, new \DateTimeZone('Europe/Berlin'));
$d->setTimeZone(new \DateTimeZone('UTC'));
$date_end = $d->format('Y-m-d H:i:s');
$event = (new \Eluceo\iCal\Domain\Entity\Event())
->setSummary('This is the title')
->setDescription('This is the description')
->setLocation(
new \Eluceo\iCal\Domain\ValueObject\Location(
'This is the location',
'This is the location'
)
)
->setOccurrence(
new \Eluceo\iCal\Domain\ValueObject\TimeSpan(
new \Eluceo\iCal\Domain\ValueObject\DateTime(
\DateTimeImmutable::createFromFormat(
'Y-m-d H:i:s',
$date_begin
),
true
),
new \Eluceo\iCal\Domain\ValueObject\DateTime(
\DateTimeImmutable::createFromFormat(
'Y-m-d H:i:s',
$date_end
),
true
)
)
);
$calendar = new \Eluceo\iCal\Domain\Entity\Calendar([$event]);
$componentFactory = new \Eluceo\iCal\Presentation\Factory\CalendarFactory();
$calendarComponent = $componentFactory->createCalendar($calendar);
header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename="file.ics"');
}
echo $calendarComponent;
die();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment