#ical #parser #rfc5545 #rfc7986

icalendar

Strongly typed iCalendar builder and parser

43 releases

0.16.10 Nov 30, 2024
0.16.8 Sep 10, 2024
0.16.2 Jul 7, 2024
0.16.0 Nov 22, 2023
0.1.0 Nov 20, 2016

#19 in Date and time

Download history 833/week @ 2024-08-20 947/week @ 2024-08-27 981/week @ 2024-09-03 1248/week @ 2024-09-10 856/week @ 2024-09-17 924/week @ 2024-09-24 896/week @ 2024-10-01 634/week @ 2024-10-08 1145/week @ 2024-10-15 1316/week @ 2024-10-22 1607/week @ 2024-10-29 1694/week @ 2024-11-05 1537/week @ 2024-11-12 1588/week @ 2024-11-19 1542/week @ 2024-11-26 1426/week @ 2024-12-03

6,310 downloads per month
Used in 17 crates (16 directly)

MIT/Apache

165KB
3.5K SLoC

iCalendar in Rust

build Crates.io contributors maintenance

version documentation license

A builder and parser for rfc5545 iCalendar.

You want to help make this more mature? Please talk to me, Pull Requests and suggestions are very welcome.

Examples

Below are two examples of how to use this library. See the examples directory as well as the documentation for many more.

Building a new Calendar

Use the builder-pattern to assemble the full calendar or event by event. Display printing produces the rfc5545 format.

use icalendar::{Calendar, CalendarDateTime, Class, Component, Event, EventLike, Property, Todo};
use chrono::{Duration, NaiveDate, NaiveTime, Utc};

// let's create a calendar
let my_calendar = Calendar::new()
    .name("example calendar")
    .push(
        // add an event
        Event::new()
            .summary("test event")
            .description("here I have something really important to do")
            .starts(Utc::now())
            .class(Class::Confidential)
            .ends(Utc::now() + Duration::days(1))
            .append_property(
                Property::new("TEST", "FOOBAR")
                    .add_parameter("IMPORTANCE", "very")
                    .add_parameter("DUE", "tomorrow")
                    .done(),
            )
            .done(),
    )
    .push(
        // add a todo
        Todo::new()
            .summary("groceries")
            .description("Buy some milk")
            .done(),
    )
    .push(
        // add an all-day event
        Event::new()
            .all_day(NaiveDate::from_ymd_opt(2016, 3, 15).unwrap())
            .summary("My Birthday")
            .description("Hey, I'm gonna have a party\nBYOB: Bring your own beer.\nHendrik")
            .done(),
    )
    .push(
        // event with utc timezone
        Event::new()
            .starts(CalendarDateTime::from(
                NaiveDate::from_ymd_opt(2024, 10, 24).unwrap()
                    .and_time(NaiveTime::from_hms_opt(20, 10, 00).unwrap())
                    .and_utc()
            ))
            .summary("Birthday Party")
            .description("I'm gonna have a party\nBYOB: Bring your own beer.\nHendrik")
            .done(),
    )
    .done();

println!("{}", my_calendar);

Parsing a Calendar

There is a feature called "parser" which allows you to read calendars again like this:

use std::fs::read_to_string;

use icalendar::{Calendar, CalendarComponent, Component};

let contents = read_to_string("fixtures/icalendar-rb/event.ics").unwrap();

let parsed_calendar: Calendar = contents.parse().unwrap();

for component in &parsed_calendar.components {
    if let CalendarComponent::Event(event) = component {
        println!("Event: {}", event.get_summary().unwrap())
    }
}

Structure

A Calendar represents a full calendar, which contains multiple Components. These may be either Events, Todos, or Venues. Components in turn have Propertys, which may have Parameters.

License

icalendar-rs is licensed under either of

at your option.

Contribution

Any help in form of descriptive and friendly issues or comprehensive pull requests are welcome!

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in icalendar-rs by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2–7.5MB
~54K SLoC