ATFutures / calendar

R interface to iCal (.ics files)
https://atfutures.github.io/calendar/
Other
41 stars 10 forks source link

Round trip fails for outlook calendar #34

Open Robinlovelace opened 5 years ago

Robinlovelace commented 5 years ago

e.g.:

# Aim: load and explore calendar
# Note: ical's support for times needs to be improved!
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(calendar)
u = "https://outlook.office365.com/owa/calendar/63f6c4e85d124df6a20656ade8e71faa@leeds.ac.uk/32e1cb4137f4414b8d7644453ec4b10414316826143036893453/calendar.ics"
download.file(u, "u.ics")
ical = calendar::ic_read("u.ics")
calendar::ic_write(ical, "u2.ics")
identical(readLines("u.ics"), readLines("u2.ics"))
#> [1] FALSE

sspa = ical %>% 
  filter(grepl("lecturing sspa", SUMMARY, ignore.case = T))

class(ical)
#> [1] "ical"       "tbl_df"     "tbl"        "data.frame"
class(sspa)
#> [1] "ical"       "tbl_df"     "tbl"        "data.frame"

sspa = sspa %>% 
  rename(DTSTART = `DTSTART;TZID=GMT Standard Time`, DTEND = `DTEND;TZID=GMT Standard Time`)
sspa$UID
#> [1] "040000008200E00074C5B7101A82E008000000007A4841CA05D9D401000000000000000\n 010000000457E19AC2AC8224990A92BA1075994F5"
sspa = calendar::ical(sspa)
calendar::ic_write(sspa, "sspa-week-22.ics")
#> Error in format.POSIXct(x, "%Y%m%d"): wrong class

Created on 2019-03-13 by the reprex package (v0.2.1)

math-mcshane commented 1 month ago

@Robinlovelace I found this same error in a different context for ic_write. Reprex below.

spurs_games = tibble::tribble(
    ~BEGIN, ~PRODID, ~VERSION, ~CALSCALE, ~METHOD, ~UID, ~DTSTART, ~DTEND, ~SUMMARY, ~LOCATION, ~END,
    "VCALENDAR", "-//ATFutures/ical //EN", "2.0", "GREGORIAN", "PUBLISH", "ical-1722515a-dd8b-4608-aa31-12a208a6903b", "20241030T203000", "20241030T230000", "Spurs at Thunder", "ESPN", "VEVENT", 
    "VCALENDAR", "-//ATFutures/ical //EN", "2.0", "GREGORIAN", "PUBLISH", "ical-4d12e9a2-d287-498f-a160-f53a81ed92ed", "20241031T200000", "20241031T223000", "Spurs at Jazz", "NBA Team Pass", "VEVENT"
  ) |> 
  calendar::ic_write(file = "temp.ics")
#> Warning in calendar::ic_write(tibble::tribble(~BEGIN, ~PRODID, ~VERSION, :
#> Coercing ic to an ical object. Use ical() first to set custom attributes.
#> Error in format.POSIXct(x, "%Y%m%d"): wrong class

Created on 2024-10-20 with reprex v2.1.1

It's possible that part of the issue is that .ics requires a certain format (see stackoverflow post), e.g., there's only one VCALENDAR and multiple VEVENTs; although this may be resolved by ic_write.

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//bobbin v0.1//NONSGML iCal Writer//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART:20100701T080000Z
DTEND:20100701T110000Z

END:VEVENT
BEGIN:VEVENT
DTSTART:20100701T120000Z
DTEND:20100701T130000Z

END:VEVENT
END:VCALENDAR
Robinlovelace commented 1 month ago

Thanks for the comment @math-mcshane. Sorry but I don't have time to work on a fix, if you or anyone figures out a fix, input/suggestions are welcome.