iCalendar规范非常简单.在阅读该链接并将其作为参考保持方便之后扩展以下内容应该是微不足道的(我故意轻易地使用该单词):
#' Create a minimal iCalendar VEVENT
#'
#' @param start,end start and end times of the event. This will be converted to
#' GMT from whatever time zone it currently is.
#' @param summary a summary of the event. This is the "title" you see in calendars.
#' @param domain something that will help the generated UUID be even more unique and
#' is generally good practice to use your org's domain name
#' @return atomic character vector ready for `writeLines()`
create_ical <- function(start, end, summary, domain="example.com") {
require(uuid, quietly = TRUE, warn.conflicts = FALSE)
sprintf(
"BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//rstats//NONSGML v1.0//EN
BEGIN:VEVENT
UID:%s@%s
DTSTAMP:%s
DTSTART:%s
DTEND:%s
SUMMARY:%s
END:VEVENT
END:VCALENDAR
", uuid::UUIDgenerate(),
domain,
format(Sys.time(), "%Y%m%dT%H%M%SZ", tz="GMT"),
format(start, "%Y%m%dT%H%M%SZ", tz="GMT"),
format(end, "%Y%m%dT%H%M%SZ", tz="GMT"),
summary
)
}
Run Code Online (Sandbox Code Playgroud)
用法:
create_ical(
as.POSIXct("2018-01-30 13:00:00", origin="1970-01-01 00:00:00"),
as.POSIXct("2018-01-30 14:00:00", origin="1970-01-01 00:00:00"),
"A good description of the event",
"somedom.org"
) -> ics_event
cat(ics_event)
## BEGIN:VCALENDAR
## VERSION:2.0
## PRODID:-//rstats//NONSGML v1.0//EN
## BEGIN:VEVENT
## UID:4ae2435e-7679-495e-9377-b6da17e0090a@somedom.org
## DTSTAMP:20180116T123051Z
## DTSTART:20180130T180000Z
## DTEND:20180130T190000Z
## SUMMARY:A good description of the event
## END:VEVENT
## END:VCALENDAR
writeLines(ics_event, "ics_event.ics")
Run Code Online (Sandbox Code Playgroud)