Fixing timezone issue with caldav.

This commit is contained in:
Burak Kaan Köse
2026-02-19 02:09:36 +01:00
parent 564cb0b16f
commit 317113a1b3
4 changed files with 199 additions and 11 deletions
+17 -2
View File
@@ -624,8 +624,8 @@ public sealed class CalDavClient : ICalDavClient
Location = sourceEvent.Location ?? string.Empty,
Start = start,
End = end,
StartTimeZone = sourceEvent.Start?.TzId ?? string.Empty,
EndTimeZone = sourceEvent.End?.TzId ?? string.Empty,
StartTimeZone = ResolveTimeZoneId(sourceEvent.Start, start),
EndTimeZone = ResolveTimeZoneId(sourceEvent.End, end),
Recurrence = recurrence,
OrganizerDisplayName = organizerDisplayName,
OrganizerEmail = organizerEmail,
@@ -638,6 +638,21 @@ public sealed class CalDavClient : ICalDavClient
};
}
private static string ResolveTimeZoneId(IDateTime sourceDateTime, DateTimeOffset parsedDateTime)
{
var explicitTimeZoneId = sourceDateTime?.TzId;
if (!string.IsNullOrWhiteSpace(explicitTimeZoneId))
return explicitTimeZoneId;
// Explicit UTC values usually don't carry TZID in CalDAV payloads.
// Preserve UTC so downstream local-time conversion stays correct.
if (parsedDateTime != default && parsedDateTime.Offset == TimeSpan.Zero)
return TimeZoneInfo.Utc.Id;
// Floating times without TZID should remain floating.
return string.Empty;
}
private static string BuildRecurrenceString(CalendarEvent sourceEvent)
{
var recurrenceLines = new List<string>();