Handling of all day events and auto calendar sync on account creation.
This commit is contained in:
@@ -180,6 +180,31 @@ public static class GoogleIntegratorExtensions
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DateTime? GetEventLocalDateTime(EventDateTime calendarEvent)
|
||||
{
|
||||
if (calendarEvent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (calendarEvent.DateTimeDateTimeOffset != null)
|
||||
{
|
||||
return DateTime.SpecifyKind(calendarEvent.DateTimeDateTimeOffset.Value.DateTime, DateTimeKind.Unspecified);
|
||||
}
|
||||
|
||||
if (calendarEvent.Date != null)
|
||||
{
|
||||
if (DateTime.TryParse(calendarEvent.Date, out DateTime eventDateTime))
|
||||
{
|
||||
return DateTime.SpecifyKind(eventDateTime, DateTimeKind.Unspecified);
|
||||
}
|
||||
|
||||
throw new Exception("Invalid date format in Google Calendar event date.");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts the timezone string from EventDateTime.
|
||||
/// Returns null for all-day events or if timezone is not specified.
|
||||
|
||||
@@ -335,6 +335,21 @@ public static class OutlookIntegratorExtensions
|
||||
}
|
||||
}
|
||||
|
||||
public static DateTime GetLocalDateTimeFromDateTimeTimeZone(DateTimeTimeZone dateTimeTimeZone)
|
||||
{
|
||||
if (dateTimeTimeZone == null || string.IsNullOrEmpty(dateTimeTimeZone.DateTime))
|
||||
{
|
||||
throw new ArgumentException("DateTimeTimeZone or DateTime is null or empty.");
|
||||
}
|
||||
|
||||
if (!DateTime.TryParse(dateTimeTimeZone.DateTime, out DateTime parsedDateTime))
|
||||
{
|
||||
throw new ArgumentException("DateTime string is not in a valid format.");
|
||||
}
|
||||
|
||||
return DateTime.SpecifyKind(parsedDateTime, DateTimeKind.Unspecified);
|
||||
}
|
||||
|
||||
private static AttendeeStatus GetAttendeeStatus(ResponseType? responseType)
|
||||
{
|
||||
return responseType switch
|
||||
|
||||
@@ -66,12 +66,14 @@ public class GmailChangeProcessor : DefaultChangeProcessor, IGmailChangeProcesso
|
||||
// We don't have this event yet. Create a new one.
|
||||
var eventStartDateTimeOffset = GoogleIntegratorExtensions.GetEventDateTimeOffset(calendarEvent.Start);
|
||||
var eventEndDateTimeOffset = GoogleIntegratorExtensions.GetEventDateTimeOffset(calendarEvent.End);
|
||||
var eventStartLocalDateTime = GoogleIntegratorExtensions.GetEventLocalDateTime(calendarEvent.Start);
|
||||
var eventEndLocalDateTime = GoogleIntegratorExtensions.GetEventLocalDateTime(calendarEvent.End);
|
||||
|
||||
double totalDurationInSeconds = 0;
|
||||
|
||||
if (eventStartDateTimeOffset != null && eventEndDateTimeOffset != null)
|
||||
if (eventStartLocalDateTime != null && eventEndLocalDateTime != null)
|
||||
{
|
||||
totalDurationInSeconds = (eventEndDateTimeOffset.Value - eventStartDateTimeOffset.Value).TotalSeconds;
|
||||
totalDurationInSeconds = (eventEndLocalDateTime.Value - eventStartLocalDateTime.Value).TotalSeconds;
|
||||
}
|
||||
|
||||
CalendarItem calendarItem = null;
|
||||
@@ -97,7 +99,7 @@ public class GmailChangeProcessor : DefaultChangeProcessor, IGmailChangeProcesso
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
Description = calendarEvent.Description ?? parentRecurringEvent.Description,
|
||||
Id = Guid.NewGuid(),
|
||||
StartDate = eventStartDateTimeOffset.Value.UtcDateTime,
|
||||
StartDate = eventStartLocalDateTime.Value,
|
||||
DurationInSeconds = totalDurationInSeconds,
|
||||
Location = string.IsNullOrEmpty(calendarEvent.Location) ? parentRecurringEvent.Location : calendarEvent.Location,
|
||||
|
||||
@@ -136,7 +138,7 @@ public class GmailChangeProcessor : DefaultChangeProcessor, IGmailChangeProcesso
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
Description = calendarEvent.Description,
|
||||
Id = Guid.NewGuid(),
|
||||
StartDate = eventStartDateTimeOffset.Value.UtcDateTime,
|
||||
StartDate = eventStartLocalDateTime.Value,
|
||||
DurationInSeconds = totalDurationInSeconds,
|
||||
Location = calendarEvent.Location,
|
||||
|
||||
|
||||
@@ -59,14 +59,15 @@ public class OutlookChangeProcessor(IDatabaseService databaseService,
|
||||
savingItem = new CalendarItem() { Id = savingItemId };
|
||||
}
|
||||
|
||||
DateTimeOffset eventStartDateTimeOffset = OutlookIntegratorExtensions.GetDateTimeOffsetFromDateTimeTimeZone(calendarEvent.Start);
|
||||
DateTimeOffset eventEndDateTimeOffset = OutlookIntegratorExtensions.GetDateTimeOffsetFromDateTimeTimeZone(calendarEvent.End);
|
||||
var eventStartLocalDateTime = OutlookIntegratorExtensions.GetLocalDateTimeFromDateTimeTimeZone(calendarEvent.Start);
|
||||
var eventEndLocalDateTime = OutlookIntegratorExtensions.GetLocalDateTimeFromDateTimeTimeZone(calendarEvent.End);
|
||||
|
||||
var durationInSeconds = (eventEndDateTimeOffset - eventStartDateTimeOffset).TotalSeconds;
|
||||
var durationInSeconds = (eventEndLocalDateTime - eventStartLocalDateTime).TotalSeconds;
|
||||
|
||||
// Store dates as UTC in the database
|
||||
// Store the wall-clock values exactly as Outlook returned them for the event timezone.
|
||||
// Timed events are converted for display later, while all-day events stay as floating dates.
|
||||
savingItem.RemoteEventId = calendarEvent.Id.WithClientTrackingId(calendarEvent.TransactionId.GetClientTrackingId());
|
||||
savingItem.StartDate = eventStartDateTimeOffset.UtcDateTime;
|
||||
savingItem.StartDate = eventStartLocalDateTime;
|
||||
savingItem.DurationInSeconds = durationInSeconds;
|
||||
|
||||
// Store the timezone information from the event
|
||||
|
||||
Reference in New Issue
Block a user