Understanding .ics file with RFC 5545
Tags: programming, computerscience
Published: 2022-08-04 15:00:37

---
canonical_url: https://dpnkr.in/blog/understanding-ics-file
description: In this blog, we will try to understand .ics file defined in RFC 5545 & create an event from scratch to add to google calendar.
---

I was stuck in a shop for hours yesterday because it was raining heavily. I got bored so decided to pass some time by connecting my work google calendar to the Apple calendar in iOS.

As I was doing that found the "Add Subscription Calendar" option which had a `SUBSCRIPTION URL` to a `.ics` file. I got curious & started reading more about `ics` files.


![Add Subscription Calendar](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tt7qf8e6sy5j393azv8v.png)

In this blog, we will demystify the `.ics` file + also create our own and integrate it into our calendars! If you're using google calendar you can export your `.ics` file from the settings.

## What's a .ics file?

The filename extension of ics is to be used for files containing calendaring and scheduling information. The file format was specified in [RFC 5545](https://datatracker.ietf.org/doc/html/rfc5545) which defined the data format for representing and exchanging calendaring and scheduling information such as events, to-dos, journal entries, and free/busy information, independent of any particular calendar service or protocol.

If you open any `.ics` file you should see something like this

```
BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
BEGIN:VEVENT
DTSTART:20220626T093000Z
DTEND:20220626T133000Z
DTSTAMP:20220630T174300Z
UID:cc071185e5d1409d93fc60098f91f3e1@google.com
CREATED:20220623T183246Z
LAST-MODIFIED:20220623T183254Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:MEETUP
END:VEVENT
END:VCALENDAR
```

On 1st impression, this kinda looks like a markup language with the BEGIN and END words. Let's see it in a tree format:

```
vcalendar
  - vevent
    - dtstart- 2022-06-26T09:30:00Z
    - dtend- 2022-06-26T13:30:00Z
    - dtstamp- 2022-06-30T17:43:00Z
    - uid- cc071185e5d1409d93fc60098f91f3e1@google.com
    - created- 2022-06-23T18:32:46Z
    - last-modified- 2022-06-23T18:32:54Z
    - sequence- 0
    - status- CONFIRMED
    - summary- MEETUP
  - prodid -//Google Inc//Google Calendar 70.9054//EN
  - version - 2.0
```

Just like HTML consists of Document Object model ics is built on Core Object which is a collection of calendaring and scheduling information. The object consists of a sequence of calendar properties and one or more calendar components.

## iCalendar Object

The above example we saw is the most basic representation of an iCalendar object. The first line and last line of the iCalendar object must contain a pair of iCalendar object delimiter strings: BEGIN & END in our case.

## Calendar Components & Properties

The body of the iCalendar object consists of a sequence of calendar properties and one or more calendar components.

Here `DTSTART` & `DTEND` are properties that specify calendar component begin/end.

```
BEGIN:VCALENDAR
...
DTSTART:20220626T093000Z
DTEND:20220626T133000Z
...
END:VCALENDAR
```

You might have noticed `VEVENT` in the ics files it's a [Calendar component](https://datatracker.ietf.org/doc/html/rfc5545#section-3.6.1) to provide a grouping of component properties that would describe an event.

Now let's create our event and add it to our google calendar. To start let's create an iCalendar Object with property VERSION set to 2.0 (latest).

```
BEGIN:VCALENDAR
VERSION:2.0
END:VCALENDAR
```

Now let's add a new event by defining an Event Component. It would begin/end with `VEVENT` we will add `UID` which is a required property. Every event has a starting/ending time to define this in an event we will use `DTSTART` and `DTEND`.

We will use the date with local time For example, the following represents January 18, 1998, at 11 PM: 19980118T230000.

You can more read about the [time formats](https://www.rfc-editor.org/rfc/rfc5545#section-3.3.4) in RFC doc.

```
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
UID:1656613525081-91990@deep.dpnkr.in
DTSTART:20220701T090000
DTEND:20220701T100000
END:VEVENT
END:VCALENDAR
```

Now that our event is in place we will add some meta properties like location, summary.

```
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
UID:1656613525081-91990@deep.dpnkr.in
DTSTART:20220701T090000
DTEND:20220701T100000
SUMMARY:Test Event
DESCRIPTION:This is test event for my blog
LOCATION:https://dpnkr.in
END:VEVENT
END:VCALENDAR
```

Now that this is in place let's try to import this in Google calendar, you can do it in settings -> import & export -> upload file. Upload the file and you should see our event created from the ics file.

![Event created via ics file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u56oxzbpp2e64r1o27xf.png)

I hope this gives your an overview of the ics file there are a lot of things like how [recurring events are created](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.10), [to-do component](https://datatracker.ietf.org/doc/html/rfc5545#section-3.6.2) which I would recommend reading more into if you're interested.


> **A quick favor:** was anything I wrote incorrectly or misspelled, or do you still have questions? Feel free to message me on [twitter](https://twitter.com/DeepankarBhade).



Until then, thanks, and have a great day.

## Read more:

- [RFC 445](https://datatracker.ietf.org/doc/html/rfc5545)
- [iCalendar Viewer](https://ratfactor.com/tools/icalendar-viewer)