ical-org / ical.net

ical.net - iCalendar library for .Net
Other
796 stars 231 forks source link

Recurrence issue #371

Closed nicuchiran closed 6 years ago

nicuchiran commented 6 years ago

Hi,

I have the following situation:

My questions are:

  1. Do you find logic my situation?
  2. If yes, is it possible to implement a fix for it?

This is my test code:

        var calendar = new Ical.Net.Calendar();

        var ev = new Ical.Net.Event()
        {
            DtStart = new Ical.Net.DataTypes.CalDateTime(new DateTime(2018, 3, 19, 8, 30, 0)),
            DtEnd = new Ical.Net.DataTypes.CalDateTime(new DateTime(2018, 3, 19, 17, 0, 0)),
        };

        ev.RecurrenceRules.Add(new Ical.Net.DataTypes.RecurrencePattern("FREQ=WEEKLY;BYDAY=WE,TH,FR"));

        calendar.Events.Add(ev);

        var occurrences = calendar.GetOccurrences(new DateTime(2018, 3, 19));
        // According to my logic, occurrences should be empty: 2018-03-19 is not a WE, TH nor FR, according to the recurrence rule.

Thank you!

rianjs commented 6 years ago

Can you post the ical text that Kendo creates?

nicuchiran commented 6 years ago

Hi,

Thanks for your quick reaction!

I didn't know exactly what do you mean by "ical text", but I found an example and I hope it's what do you need. If not, please advise! So please find attached my file. console.log

rianjs commented 6 years ago

Yeah, when Kendo serializes the event(s), it will produce something like this:

BEGIN: VCALENDAR
VERSION:4.0
PRODID: -//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
BEGIN:VEVENT
DTEND:20160704T172520
DTSTAMP:20160704T162520
DTSTART:20160704T162520
RRULE:FREQ=DAILY;COUNT=5
SEQUENCE: 0
UID: f4693a88-0a57-4761-b949-8822b8a507d2
END:VEVENT
END:VCALENDAR

Can you paste the text that Kendo creates? I think you're saving them to the database?

nicuchiran commented 6 years ago

Hi,

I used a script from here to export the events (https://docs.telerik.com/kendo-ui/controls/scheduling/scheduler/how-to/export/ical-export), but the format generated is slightly different than yours:

UID:0@default
CLASS:PUBLIC
DESCRIPTION: Normal work schedule
DTSTAMP;VALUE=DATE-TIME:20180328T102102
DTSTART;VALUE=DATE-TIME:20180320T083000
DTEND;VALUE=DATE-TIME:20180320T170000
LOCATION:
SUMMARY;LANGUAGE=en-us:8:30 - 17:00 Shift with 12:30 - 13:00 Break ( Normal work schedule)
TRANSP:TRANSPARENT
END:VEVENT

If I inspect the events inside the scheduler and put it in the format you provided, it would look like this:

VERSION:4.0
PRODID: -//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
BEGIN:VEVENT
DTEND:VALUE=DATE-TIME:20180320T170000
DTSTAMP:VALUE=DATE-TIME:20180328T102102
DTSTART:VALUE=DATE-TIME:20180320T083000
RRULE:FREQ=WEEKLY;UNTIL=20180331T215959Z;BYDAY=WE,TH,FR
SEQUENCE:0
UID:ca25d651-fd20-4a4e-87f2-8bad0a71d6f8
END:VEVENT
END:VCALENDAR

Is this ok?

minichma commented 6 years ago

Unfortunately rfc 5545 leaves this case undefined:

The recurrence set generated with a "DTSTART" property value that doesn't match the pattern of the rule is undefined.

However, I agree, that one would intuitively expect, and that it makes a lot of sense, that dtstart itself isn't returned if it doesn't match the rrule. It also seems that most libs implement it that way. So +1 for implementing iCal.net that way too.

nicuchiran commented 6 years ago

So, can we expect for this implementation?

rianjs commented 6 years ago

This is a Telerik idiosyncrasy that I worked around in one of our applications this week. Telerik hard-codes that all UNTIL values are UTC, which is bogus.

The workaround is to manually change each IAppointment’s RecurUntil value, and specify a DateTimeKind of Local using DateTime.SpecifyKind. That means you’ll need a filter all values coming from Telerik. There is no other way.

This is a Telerik bug. I disassembled the Telerik DLLs and found the specific methods that do the wrong thing(s). It’s very frustrating. I spent hours unwinding the problem, but it’s part of a larger problem with Telerik controls: they’re really bad at handling anything time zone-related.