Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialized EXDATE is unpermitted PERIOD value type when originated as System.DateTime #591

Open
jvraines opened this issue Sep 1, 2024 · 5 comments

Comments

@jvraines
Copy link

jvraines commented Sep 1, 2024

This code

Calendar myCal = new Calendar();
CalendarEvent myEvent = new CalendarEvent {
    Start = new CalDateTime(2024, 12, 1, 12, 0, 0),
    End = new CalDateTime(2025, 1, 1, 18, 0, 0),
    RecurrenceRules = new List<RecurrencePattern> {
                            new RecurrencePattern {
                                Frequency = FrequencyType.Daily
                            }
                      }
};
myEvent.ExceptionDates.Add(new PeriodList { 
    new CalDateTime(2024, 12, 25)
    new CalDateTime(new DateTime(2024, 12, 26))
});
myCal.Events.Add(myEvent);
Console.WriteLine(new CalendarSerializer().SerializeToString(myCal));

produces

BEGIN:VCALENDAR
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
VERSION:2.0
BEGIN:VEVENT
DTEND:20250101T180000
DTSTAMP:20240901T232258Z
DTSTART:20241201T120000
EXDATE:20241225T000000,20241226/P1D
RRULE:FREQ=DAILY
SEQUENCE:0
UID:d65129f0-d00c-46d1-a7d2-81a73a41990d
END:VEVENT
END:VCALENDAR

The first excluded date is an acceptable DATE-TIME value type. The second, however, is a PERIOD value type which is not permitted by the EXDATE spec.

@RemcoBlok
Copy link

Another (presumably related) issue is that if you create the CalDateTime with a TZID (when it is an exception date for an event that is not an all-day event, but for a specific time on the day), iCal.NET does not serialize the TZID with the EXDATE. When deserializing this may result in GetOccurrences() producing an occurrence on the EXDATE, or what was supposed to be the EXDATE if it did not loose the TZID.

What can I do as a temporary workaround here? Fix the EXDATE after deserializing? Or remove the occurrence from the result of GetOccurrences()?

@axunonb
Copy link
Collaborator

axunonb commented Oct 17, 2024

Hi Remco, please kindly follow the Filing a bug report and submit a new issue. This makes it more simple and faster to understand the whole context of what your doing. If you think, ,your issue is related to this one, add a reference.

@jvraines
Copy link
Author

@RemcoBlok Which CalDateTime constructor are you using? One with string tzId? If so, you could try passing appropriate time values to the constructor without that parameter and see what happens.

@RemcoBlok
Copy link

Thanks for your reply. I created a separate issue #614

@axunonb
Copy link
Collaborator

axunonb commented Oct 20, 2024

For EXDATE with a timezone it looks like the parameter for the timezone gets recognized and set, but not processed when rendering to a string. Als EXDATE with different timezones is not implemented correctly.
We'll look closer into that, also in context of the referenced like #614, #588

else if (!string.IsNullOrWhiteSpace(dt.TzId))
{
dt.Parameters.Set("TZID", dt.TzId);
}
DateTime.SpecifyKind(dt.Value, kind);
// FIXME: what if DATE is the default value type for this?
// Also, what if the DATE-TIME value type is specified on something
// where DATE-TIME is the default value type? It should be removed
// during serialization, as it's redundant...
if (!dt.HasTime)
{
dt.SetValueType("DATE");
}
var value = new StringBuilder();
value.Append($"{dt.Year:0000}{dt.Month:00}{dt.Day:00}");
if (dt.HasTime)
{
value.Append($"T{dt.Hour:00}{dt.Minute:00}{dt.Second:00}");
if (dt.IsUtc)
{
value.Append("Z");
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants