IcsGenerator by thausmann

This module can generate ICS files.


The module can generate basic ICS calendar strings and files.

The module simply extends WireData. It has these properties and default values:

$this->set('date', 'now');
$this->set('dateEnd', 'now + 60 minutes');
$this->set('summary', 'ICS Calendar File');
$this->set('description', '');
$this->set('location', '');
$this->set('url', '');
$this->set('timezone', new \DateTimeZone(date_default_timezone_get()));
  • date / dateEnd should be a PHP DateTime object or a string.
  • Date strings will be passed to DateTime constructor.
  • Date strings will use the set timezone.
  • Final output will be converted to UTC (Z timestamp)
// get the module
$icsgen = wire()->modules->IcsGenerator;

// set single properties (date strings)
$icsgen->set('date',    '2033-12-24 12:00');
$icsgen->set('dateEnd', '2033-12-24 14:00');

// set single properties (DateTime)
$icsgen->set('date',    new \DateTime('2033-12-24 12:00'));
$icsgen->set('dateEnd', new \DateTime('2033-12-24 14:00'));

// the set timezone will only impact time strings!
$icsgen->set('timezone', new \DateTimeZone('Europe/Berlin'));
$icsgen->set('date',    'now');
$icsgen->set('dateEnd', 'now + 60 minutes');

// set timezone will be ignored when string is a unix timestamp or contains a timezone
$icsgen->set('date',    '@946684800');
$icsgen->set('date',    '2010-01-28T15:00:00+02:00');

// set timezone will not impact DateTime!
// construct your DateTime with DateTimeZone instead
$icsgen->set('date',    new \DateTime('2033-12-24 12:00', new \DateTimeZone('Asia/Dubai')));
$icsgen->set('dateEnd', new \DateTime('2033-12-24 12:00', new \DateTimeZone('Europe/Paris')));

// set multiple properties at once
    'date' => '2033-12-24 12:00',
    'dateEnd' => '2033-12-24 14:00',
    'summary' => 'Event Title',
    'description' => 'Event Description',

// get ICS string
$str = $icsgen->getString();

// get ICS object
$ics = $icsgen->getICS();

// get path to a temporary .ics file
// using wire()->files->tempDir
$path = $icsgen->getFile();

// get path to a temporary .ics file by ID
// this is useful if you need the same ICS multiple times in one request
// (same file id will only be created once)
$path = $icsgen->getFileByID('christmas-2033');

// example: send email with ics file
$mail = wireMail();
$mail->attachment($path, 'calendar.ics');
$mail->subject('ICS Demo');
$mail->body('This is a ICS demo.');
$numSent = $mail->send();

Code is heavily based on https://gist.github.com/jakebellacera/635416 with some improvements.

PRs are open.

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Twitter updates

  • Introduction to an invoice application profile being built in ProcessWire: More
    30 September 2022
  • Stumbling upon a really nice ProcessWire-powered website, plus core updates including API improvements for ProcessWire forms— More
    9 September 2022
  • Useful new dot-and-bracket syntax options added for page.get() method— More
    2 September 2022

Latest news

  • ProcessWire Weekly #437
    In the 437th issue of ProcessWire Weekly we're going to check out the latest core updates, forum highlights and online resources, and more. Read on!
    Weekly.pw / 24 September 2022
  • Multi-language field translation export/import
    In this post we cover the details of a new module that enables export and import capabilities for multi-language fields in ProcessWire.
    Blog / 5 August 2022
  • Subscribe to weekly ProcessWire news

“Indeed, if ProcessWire can be considered as a CMS in its own right, it also offers all the advantages of a CMF (Content Management Framework). Unlike other solutions, the programmer is not forced to follow the proposed model and can integrate his/her ways of doing things.” —Guy Verville, Spiria Digital Inc.