cozy / cozy-ical

ICal Parser and Calendar models for Cozy Cloud
http://cozy.io
Other
29 stars 11 forks source link

Date/time VEvent with RRule is broken wrt time zones #43

Closed konrad-garus closed 8 years ago

konrad-garus commented 8 years ago

I have a bunch of date/time VEvents. Some of them have RRule, others don't:

[
{ calendarTitle: 'Title',
  calendarOrganization: 'Org',
  stampDate: Tue Feb 02 2016 17:57:37 GMT+0100 (CET),
  uid: 'TRAIN-3',
  summary: 'Something Third',
  description: 'Description: ',
  rrule: null,
  startDate: { /* moment-timezone object here */ },
  endDate: { /* moment-timezone object here */ },
  allDay: false },
{ calendarTitle: 'Title',
  calendarOrganization: 'Org',
  stampDate: Tue Feb 02 2016 17:57:37 GMT+0100 (CET),
  uid: 'TRAIN-2',
  summary: 'test w date held',
  description: 'Description: ',
  rrule: { freq: 3, count: 3 },
  startDate: { /* moment-timezone object here */ },
  endDate: { /* moment-timezone object here */ },
  allDay: false }
]

One of them gets exported in absolute time zone (as expected), the other in local:

BEGIN:VEVENT
UID:TRAIN-3
DTSTAMP:20160202T164730Z
DTSTART:20151119T064500Z
DTEND:20151119T160000Z
DESCRIPTION:Description: 
SUMMARY:Something Third
END:VEVENT
BEGIN:VEVENT
UID:TRAIN-2
DTSTAMP:20160202T164730Z
DTSTART:20151113T140000
DTEND:20151113T220000
DESCRIPTION:Description: 
RRULE:FREQ=DAILY;COUNT=3
SUMMARY:test w date held
END:VEVENT

Looking at this if/else/else here: https://github.com/cozy/cozy-ical/blob/master/src/index.coffee#L450 - the handling for rrule is very different, and much shorter than the following "else" branch.

I can work around it by explicitly providing time zone all the time, but the library should be consistent and if it doesn't require it in one case, it should behave the same way in the other.

clochix commented 8 years ago

Thanks for reporting @konrad-garus. I ping @jsilvestre who's our ICAL expert

jsilvestre commented 8 years ago

Hello @konrad-garus, Sorry for the late answer, I was on vacations :)

The behaviour might seem inconsistent, but it's actually intended. When you have a recurring event, it must use the local timezone in order to resist to change when a daylight saving occurs. See https://github.com/cozy/cozy-calendar/wiki/Generalities-about-calendar-components,-iCal-and-date-handling-in-js#2-recurring-event. That's why you must specify the timezone whenever you have a recurring event. The idea is that you can "whatever the time of the year it is, this event happens on one date, at a specific time, for a given timezone, and this time never changes no matter what, for the given timezone)".

I hope I am being clear enough, feel free to ask more questions, and tell me If I didn't answer your concern properly.

Thank you!

konrad-garus commented 8 years ago

Thank you, that makes a lot of sense!