A small library for reading and writing ICalendar files.
Bug fixes may be accepted but no new features will be added. If you wish to add new features I recommend creating and publishing a fork. If an active fork is created I will direct users from this project to the new one.
The package can be installed by adding :icalendar to your list of dependencies
in mix.exs:
def deps do
[
{:icalendar, "~> 1.1.0"}
]
endevents = [
%ICalendar.Event{
summary: "Film with Amy and Adam",
dtstart: {{2015, 12, 24}, {8, 30, 00}},
dtend: {{2015, 12, 24}, {8, 45, 00}},
description: "Let's go see Star Wars.",
location: "123 Fun Street, Toronto ON, Canada"
},
%ICalendar.Event{
summary: "Morning meeting",
dtstart: Timex.now,
dtend: Timex.shift(Timex.now, hours: 3),
description: "A big long meeting with lots of details.",
location: "456 Boring Street, Toronto ON, Canada"
},
]
ics = %ICalendar{ events: events } |> ICalendar.to_ics
File.write!("calendar.ics", ics)
# BEGIN:VCALENDAR
# CALSCALE:GREGORIAN
# VERSION:2.0
# BEGIN:VEVENT
# DESCRIPTION:Let's go see Star Wars.
# DTEND:20151224T084500Z
# DTSTART:20151224T083000Z
# LOCATION: 123 Fun Street\, Toronto ON\, Canada
# SUMMARY:Film with Amy and Adam
# END:VEVENT
# BEGIN:VEVENT
# DESCRIPTION:A big long meeting with lots of details.
# DTEND:20151224T223000Z
# DTSTART:20151224T190000Z
# LOCATION:456 Boring Street\, Toronto ON\, Canada
# SUMMARY:Morning meeting
# END:VEVENT
# END:VCALENDARThe library also supports VTODO components for task management:
# Create todos with various properties
todos = [
%ICalendar.Todo{
summary: "Buy groceries",
due: Timex.to_datetime({{2023, 12, 25}, {18, 00, 00}}),
priority: 1,
status: "needs-action"
},
%ICalendar.Todo{
summary: "Complete project",
dtstart: Timex.to_datetime({{2023, 12, 20}, {9, 00, 00}}),
due: Timex.to_datetime({{2023, 12, 25}, {17, 00, 00}}),
percent_complete: 50,
priority: 2,
status: "in-process",
description: "Finish the quarterly project"
}
]
# Generate ICS with todos
ics = %ICalendar{todos: todos} |> ICalendar.to_ics
File.write!("tasks.ics", ics)
# Mix events and todos in the same calendar
calendar = %ICalendar{
events: events,
todos: todos
}
ics = calendar |> ICalendar.to_ics
File.write!("mixed_calendar.ics", ics)
# Parse calendars with todos
calendar = ICalendar.from_ics(File.read!("tasks.ics"))
todos = calendar.todos
events = calendar.eventssummary: Task titledescription: Detailed descriptiondtstart: Start date/timedue: Due date/timecompleted: Completion date/timepercent_complete: Completion percentage (0-100)status: Status ("needs-action", "in-process", "completed", "cancelled")priority: Priority level (1-9, where 1 is highest)location: Locationurl: Related URLuid: Unique identifiercategories: List of categoriesclass: Classification ("public", "private", "confidential")comment: Commentsorganizer: Organizer informationattendees: List of attendeesrelated_to: Related task UIDrrule: Recurrence ruleexdates: Exception datesduration: Durationsequence: Revision sequence number
Copyright (c) 2015 Louis Pilfold
This library is released under the MIT License. See the LICENSE.md file for further details.