-
Good work on the progress on V5! I found a regression in the 5.0.0-daily.3 pre-release though. In V4 I could specify a timezone for all-day events (where the start and end have no time component) and ical.net would serialize the timezone for all-day events.
using the following code Calendar calendar = new Calendar();
string timeZoneId = "Pacific Standard Time";
CalendarEvent myEvent = new CalendarEvent();
myEvent.Start = new CalDateTime(2024, 11, 3, timeZoneId);
myEvent.Start.HasTime = false;
myEvent.End = new CalDateTime(2024, 11, 4, timeZoneId);
myEvent.End.HasTime = false;
Debug.Assert(myEvent.IsAllDay);
calendar.Events.Add(myEvent);
CalendarSerializer serializer = new CalendarSerializer();
string schedulerData = serializer.SerializeToString(calendar); In V5 ical.net no longer serializes the timezone for all-day events
using the following code Calendar calendar = new Calendar();
string timeZoneId = "Pacific Standard Time";
DateTime start = new DateTime(2024, 11, 3);
DateTime end = new DateTime(2024, 11, 4);
CalendarEvent myEvent = new CalendarEvent();
myEvent.Start = new CalDateTime(start, timeZoneId, hasTime: false);
myEvent.End = new CalDateTime(end, timeZoneId, hasTime: false);
Debug.Assert(myEvent.IsAllDay);
calendar.Events.Add(myEvent);
CalendarSerializer serializer = new CalendarSerializer();
string schedulerData = serializer.SerializeToString(calendar); It is important for me to specify a timezone for all-day events. When I have an all-day event specified in the PST timezone and view this event in a calendar user-interface component in the GMT timezone then it should not show it as an all-day event in the GMT timezone. Perhaps if I have an all-day event without specifying a timezone, it might show as an all-day event in any timezone (or only the system local timezone), but when I explicitly specify a timezone for the all-day event then it is an all-day event in that timezone only, because the start of the day in PST is not at the same (UTC) time as the start of the day in GMT (even daylight saving transitions in PST and GMT are not on the same day). Especially when I look for overlapping occurrences of events in different timezones, I need to know the timezone for all-day events the same as for non-all-day events. Note that in V5 the constructors of CalDateTime do not make it easy to specify a timezone for an all-day event. It would be good if the overloads that take a DateOnly or (year, month, day) would also accept an optional timezone. I also wonder if I should create the CalendarEvent with a Duration instead of an End date, but I believe it should work with an End date as well as long as I set hasTime to false and the effective duration is one day (or more). Please confirm. It would also be good if CalendarEvent could have read-only properties for EffectiveEnd and EffectiveDuration like the CalPeriod of an Occurrence. CalendarEvent, CalPeriod and Duration could also benefit from a read-only ExactDuration property that returns a TimeSpan. Thanks -Remco |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 11 replies
-
Hi! Would you agree that as of RFC5555 section 3.3.4, a DATE property cannot have a timezone? |
Beta Was this translation helpful? Give feedback.
-
Hi! I think that section is about a DATE value, not a DATE property. When I look at the DTSTART and DTEND properties, I see they can have either a DATE or DATE-TIME value, but also parameters like TZID. It is not clear to me that you cannot use a TZID parameter with a DATE value. So I think that you can use a TZID parameter with a DATE value. |
Beta Was this translation helpful? Give feedback.
-
A certain evidence could be, that Google Calendar and Microsoft Outlook don't add a timezone to all-day events as well. Just double-checked that this is the case.
|
Beta Was this translation helpful? Give feedback.
-
To fully address your use case: If you want the all-day event to be kind of associated with a specific timezone, you can add a default VTIMEZONE to the calendar. This might have the same effect as the non-compliant TZID added to a DATE value type. |
Beta Was this translation helpful? Give feedback.
-
Happy to discuss and explore solutions. With a default timezime for the calendar you cannot have one all-day event in GMT and another all-day event in PST and my application figuring out which hours overlap. All that should be independent of the local system timezone. I can run the application on a developer PC in CET and my colleague on their developer PC in EST and a (build) server in the cloud run the application in UTC. Was it really the intention of the icalendar standard to assume the local system timezone for an all-day event where ever that may be? A timezone for an all-day event may not have any effect in ical.net itself, but is an essential piece of information my application wants to persist. But perhaps, as you suggest, I should not use a DATE, but a DATE-TIME. In V4 an event would only be an all-day event if the Start did not have time component. In V5 can I specify an all-day event using a Start with a time component (always midnight)? When specifying a time component, how can I indicate when I want to apply one-day Period sementics vs 24-hour Duration semantics (I'm using NodaTime's definition of Period vs Duration here)? For one-day Period semantics I must create the event using a one-day ical.net Duration, and for 24-hour Duration semantics I must create the event using an End that is 24 hours after the Start. I seem to recall reading that ical.net determinies the effective duration (using either End or Duration) and if that is (integer values of ) one day it will apply one-day Period sementics, leaving the programmer no way to indicate 24-hour Duration semantics, right? Knowing whether to apply one-day Period sementics vs 24-hour duration sementics is especially relevant with recurring all-day events and generating occurrences after daylight-saving transitions? For daylight-saving transitions you must know the timezone. |
Beta Was this translation helpful? Give feedback.
-
Is it posiible to update the CalendarEvent.IsAllDay property to bool isAllDay = calendarEvent.Start.HasTime == false ||
calendarEvent.Start.Time == TimeOnly.MinValue &&
calendarEvent.Duration != null &&
calendarEvent.Duration.Value.HasTime == false; |
Beta Was this translation helpful? Give feedback.
The differences between 24h vs 1d semantics have been addressed in #680. You can specify 24h (aka 'exact') semantics by specifying the duration via
DTEND
or via a time-onlyDuration
(e.g.Duration.FromHours(24)
). You can specify 1d (aka 'nominal') semantics via a date-onlyDuration
(e.g.Duration.FromDays(1)
).Regarding
DATE
withTZID
the RFC is quite clear in section 3.2.19: