ical.net icon indicating copy to clipboard operation
ical.net copied to clipboard

RecurrencePattern not serialized correctly

Open derekantrican opened this issue 6 years ago • 2 comments

Code to reproduce:

string rrule = "RRULE:FREQ=WEEKLY;WKST=MO;UNTIL=20190831;BYDAY=FR,SA,SU";
RecurrencePattern pattern = new RecurrencePattern(rrule);
string serializedRRULE = pattern.ToString(); //FREQ=WEEKLY;UNTIL=20190831T000000;BYDAY=FR,SA,SU

In the above code, when calling pattern.ToString();, the result is FREQ=WEEKLY;UNTIL=20190831T000000;BYDAY=FR,SA,SU when it really should be FREQ=WEEKLY;UNTIL=20190831T000000Z;BYDAY=FR,SA,SU (note the Z)

derekantrican avatar Sep 17 '19 14:09 derekantrican

Possibly it could be better to give RecurrencePattern a concept of timezone as, per the docs:

Furthermore, if the "DTSTART" property is specified as a date with local time, then the UNTIL rule part MUST also be specified as a date with local time. If the "DTSTART" property is specified as a date with UTC time or a date with local time and time zone reference, then the UNTIL rule part MUST be specified as a date with UTC time. In the case of the "STANDARD" and "DAYLIGHT" sub-components the UNTIL rule part MUST always be specified as a date with UTC time. If specified as a DATE-TIME value, then it MUST be specified in a UTC time format.

derekantrican avatar Sep 17 '19 14:09 derekantrican

Note that this can be solved by doing:

string rrule = "RRULE:FREQ=WEEKLY;WKST=MO;UNTIL=20190831;BYDAY=FR,SA,SU";
RecurrencePattern pattern = new RecurrencePattern(rrule);
pattern.Until = DateTime.SpecifyKind(pattern.Until, DateTimeKind.Utc);
string serializedRRULE = pattern.ToString(); //FREQ=WEEKLY;UNTIL=20190831T000000Z;BYDAY=FR,SA,SU

But that seems improper and inflexible

derekantrican avatar Sep 17 '19 15:09 derekantrican