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

Incorrect Timezone Handling in CalDAV Synchronization Causes Time Shifts #1626

Closed
wants to merge 1 commit into from

Conversation

sandro-byte32
Copy link

Description:

When syncing events with CalDAV, there is a recurring issue where event times are shifted by one hour. This happens because the synchronization process incorrectly assumes that DTSTART and DTEND values are in UTC, even when they are actually in the local timezone (e.g., Europe/Vienna).

Steps to Reproduce:

Create an event in the calendar with a start time of 09:00 in Europe/Vienna. Synchronize the event with CalDAV.
Observe that the start time in the synchronized system is incorrectly shifted to 10:00. Root Cause Analysis:

The issue arises in the convert_caldav_event_to_array_event method:

private function convert_caldav_event_to_array_event(VEvent $vevent, DateTimeZone $timezone_object): array {
    $utc_timezone_object = new DateTimeZone('UTC'); // UTC is incorrectly assumed here
    
    $start_date_time_object = new DateTime((string) $vevent->DTSTART, $utc_timezone_object);
    $start_date_time_object->setTimezone($timezone_object);
}

This method assumes all DTSTART and DTEND values are in UTC. However, in many cases:

The DTSTART value contains a timezone identifier (e.g., TZID=Europe/Vienna). The value is implicitly in the local timezone, but this is not indicated in the data. As a result, the synchronization logic performs an unnecessary conversion from UTC to the local timezone, causing an unwanted shift.

…ifts

Description:

When syncing events with CalDAV, there is a recurring issue where event times are shifted by one hour. This happens because the synchronization process incorrectly assumes that DTSTART and DTEND values are in UTC, even when they are actually in the local timezone (e.g., Europe/Vienna).

Steps to Reproduce:

Create an event in the calendar with a start time of 09:00 in Europe/Vienna.
Synchronize the event with CalDAV.
Observe that the start time in the synchronized system is incorrectly shifted to 10:00.
Root Cause Analysis:

The issue arises in the convert_caldav_event_to_array_event method:

private function convert_caldav_event_to_array_event(VEvent $vevent, DateTimeZone $timezone_object): array {
    $utc_timezone_object = new DateTimeZone('UTC'); // UTC is incorrectly assumed here
    
    $start_date_time_object = new DateTime((string) $vevent->DTSTART, $utc_timezone_object);
    $start_date_time_object->setTimezone($timezone_object);
}
This method assumes all DTSTART and DTEND values are in UTC. However, in many cases:

The DTSTART value contains a timezone identifier (e.g., TZID=Europe/Vienna).
The value is implicitly in the local timezone, but this is not indicated in the data.
As a result, the synchronization logic performs an unnecessary conversion from UTC to the local timezone, causing an unwanted shift.
@alextselegidis
Copy link
Owner

Hello!

Thanks for this PR.

I will review and merge accordingly.

Alex Tselegidis, Easy!Appointments Creator
Need a customization? Get a free quote!

@alextselegidis
Copy link
Owner

Hello!

I had to make some minor adjustments but did merge the logic for parsing the timezone values.

Thanks for providing this PR.

Alex Tselegidis, Easy!Appointments Creator
Need a customization? Get a free quote!

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

Successfully merging this pull request may close these issues.

2 participants