Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

How to associate a timezone to an all-day event #716

Closed
RemcoBlok opened this issue Feb 7, 2025 · 4 comments
Closed

How to associate a timezone to an all-day event #716

RemcoBlok opened this issue Feb 7, 2025 · 4 comments

Comments

@RemcoBlok
Copy link

RemcoBlok commented Feb 7, 2025

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.

BEGIN:VCALENDAR
PRODID:-//github.com/ical-org/ical.net//NONSGML ical.net 4.0//EN
VERSION:2.0
BEGIN:VEVENT
DTEND;TZID=Pacific Standard Time;VALUE=DATE:20241104
DTSTAMP:20250207T121642Z
DTSTART;TZID=Pacific Standard Time;VALUE=DATE:20241103
SEQUENCE:0
UID:e51ce49f-ba0f-41e4-b3a8-8fee04180c33
END:VEVENT
END:VCALENDAR

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

BEGIN:VCALENDAR
PRODID:-//github.com/ical-org/ical.net//NONSGML ical.net 4.0//EN
VERSION:2.0
BEGIN:VEVENT
DTEND;VALUE=DATE:20241104
DTSTAMP:20250207T122102Z
DTSTART;VALUE=DATE:20241103
SEQUENCE:0
UID:a3eadb5a-5d4e-47ef-a13d-d5d66c94911e
END:VEVENT
END:VCALENDAR

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

@RemcoBlok RemcoBlok added the bug label Feb 7, 2025
@axunonb axunonb added investigating and removed bug labels Feb 7, 2025
@axunonb
Copy link
Collaborator

axunonb commented Feb 7, 2025

Hi! Would you agree that as of RFC5555 section 3.3.4, a DATE property cannot have a timezone?
That's why we have this implementation, never mind the implementation in v4.

@RemcoBlok
Copy link
Author

RemcoBlok commented Feb 7, 2025

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.

@axunonb
Copy link
Collaborator

axunonb commented Feb 8, 2025

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.
So we're confident that the implementation in v5 is compliant to RFC5545, while adding a timezone is not.
When a timezone should apply, a DATE-TIME value type is to be used instead of DATE.

BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 16.0 MIMEDIR//EN
VERSION:2.0
METHOD:PUBLISH
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
BEGIN:VEVENT
CLASS:PUBLIC
CREATED:20250208T095053Z
DESCRIPTION: \n
DTEND;VALUE=DATE:20250204
DTSTAMP:20250208T095053Z
DTSTART;VALUE=DATE:20250203
LAST-MODIFIED:20250208T095053Z
PRIORITY:5
RRULE:FREQ=WEEKLY;COUNT=25;BYDAY=MO
SEQUENCE:0
SUMMARY;LANGUAGE=en:Test all-day event
TRANSP:TRANSPARENT
UID:040000008200E00074C5B7101A82E0080000000040B8BBE8157ADB01000000000000000
	0100000002B895833F77B2A4EA69F2887A3F5A198
X-MICROSOFT-CDO-BUSYSTATUS:FREE
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-DISALLOW-COUNTER:FALSE
X-MS-OLK-CONFTYPE:0
BEGIN:VALARM
TRIGGER:-PT1080M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR

@axunonb
Copy link
Collaborator

axunonb commented Feb 10, 2025

To fully address your use case: If you want the all-day event to be associated with a specific timezone, you can add a default VTIMEZONE to the calendar.

@axunonb axunonb changed the title V5 regression: All-day event should serialize timezone How to associate a timezone to an all-day event Feb 10, 2025
@ical-org ical-org locked and limited conversation to collaborators Feb 10, 2025
@axunonb axunonb converted this issue into discussion #717 Feb 10, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants