#ical #ics #calendar #read-write

bin+lib web_ical

web_ical 是一个易于使用的 iCalendar Rust 库。它的目标是以一种对开发者友好的方式读取和写入 iCalendar 网络文件(如 Google Calendar、Airbnb Calendar 等)的数据。

1 个不稳定版本

0.1.2 2019年7月13日
0.1.1 2019年7月10日
0.1.0 2019年7月10日

11#ics 中排名

每月下载量 28

MIT/Apache

27KB
392

web_ical

web_ical 是一个易于使用的 iCalendar Rust 库。它的目标是以一种对开发者友好的方式读取和写入 iCalendar 网络文件(如 Google Calendar、Airbnb Calendar 等)的数据。

示例 1

extern crate web_ical;

use web_ical::Calendar;

fn main() {
    let icals = Calendar::new("http://ical.mac.com/ical/US32Holidays.ics");

    for ical in &icals.events{
         println!("Event: {}", ical.summary);
         println!("Started: {}", ical.dtsart.format("%a, %e %b %Y - %T"));
    }
}

示例 2

extern crate web_ical;

use web_ical::Calendar;

fn main() {
    let icals = Calendar::new("http://ical.mac.com/ical/US32Holidays.ics");
     println!("UTC now is: {}", icals.events[0].dtsart); 
     println!("UTC now in RFC 2822 is: {}", icals.events[0].dtsart.to_rfc2822()); 
     println!("UTC now in RFC 3339 is: {}", icals.events[0].dtsart.to_rfc3339()); 
     println!("UTC now in a custom format is: {}", icals.events[0].dtsart.format("%a %b %e %T %Y"));
}

创建 iCalendar

创建自己的 iCalendar 实例

let mut ical =  Calendar::create(
    "-//My Business Inc//My Calendar 70.9054//EN",
    "2.0",
    "GREGORIAN",
    "PUBLISH",
    "[email protected]",
    "America/New_York");

添加事件

将事件添加到日历中。

 let mut start_cal:  DateTime<Utc> = Utc::now();
  let date_tz: DateTime<Utc> = Utc::now();
 let start = date_tz.checked_add_signed(Duration::days(2));
   
 match start {
       Some(x) => {
              start_cal = x;
       },
       None => ()
 }
 let own_event = Events{ 
                    
                    dtsart:         start_cal,
                    dtend:          start_cal,
                    dtstamp:        date_tz,
                    uid:            "[email protected]".to_string(),
                    created:        date_tz,
                    description:    "The description".to_string(),
                    last_modified:  date_tz,
                    location:       "Homestead FL".to_string(),
                    sequence:       0,
                    status:         "CONFIRMED".to_string(),
                    summary:        "My business (Not available)".to_string(),
                    transp:         "OPAQUE".to_string()
                    
    };
 let mut ical =  Calendar::create(
                       "-//My Business Inc//My Calendar 70.9054//EN",
                       "2.0",
                       "GREGORIAN",
                       "PUBLISH",
                       "[email protected]",
                       "America/New_York");
 
 ical.add_event(own_event);
 println!("{}", ical.events[0].summary);
 

将 iCalendar 导出为文件

将 iCalendar 导出为文件。


 match ical.export_ics("ical.ics"){
       Ok(_) => println!("OK"),
       Err(_) => panic!("Err")
 };

依赖项

~24MB
~503K SLoC