-
Notifications
You must be signed in to change notification settings - Fork 4
Add support for timezone and all day events #5
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,7 @@ public function process_attachment(&$content, &$message, &$a) | |
| $date_format = $rcmail->config->get('date_format', 'D M d, Y'); | ||
| $time_format = $rcmail->config->get('time_format', 'h:ia'); | ||
| $combined_format = $date_format . ' ' . $time_format; | ||
| $ymd = 'Y-m-d'; | ||
|
|
||
| // Parse event | ||
| $ics = $message->get_part_body($a->mime_id); | ||
|
|
@@ -63,20 +64,47 @@ public function process_attachment(&$content, &$message, &$a) | |
| // Make sure we have events | ||
| if (!$ical->hasEvents()) return; | ||
|
|
||
| // Crete timezone objects for calendar timezone and RoundCube UI timezone | ||
| try { | ||
| $ui_tz = new DateTimeZone($rcmail->config->get('timezone')); | ||
| } catch (Exception $e) { | ||
| $ui_tz = new DateTimeZone(DateTimeZone::UTC); | ||
| } | ||
| try { | ||
| $ical_tz = new DateTimeZone($ical->calendarTimeZone(true)); | ||
| } catch (Exception $e) { | ||
| // Use UI timezone if the calendar have no timezone specified | ||
| $ical_tz = $ui_tz; | ||
| } | ||
|
|
||
| // Get first event | ||
| foreach ($ical->events() as &$event) { | ||
| $dtstart = $event->dtstart_array[2]; | ||
| $dtend = $event->dtend_array[2]; | ||
| $dtstr = $rcmail->format_date($dtstart, $combined_format) . ' - '; | ||
|
|
||
| // Dont double date if same | ||
| $df = 'Y-m-d'; | ||
| if (date($df, $dtstart) === date($df, $dtend)) { | ||
| $dtstr .= $rcmail->format_date($dtend, $time_format); | ||
| $is_all_day = isset($event->dtstart_array[0]['VALUE']) && $event->dtstart_array[0]['VALUE'] === 'DATE'; | ||
|
|
||
| if ($is_all_day) { | ||
| // All day events should use UI timezone to avoid turning dates | ||
| $dtstart = new DateTime($event->dtstart, $ui_tz); | ||
| $dtend = new DateTime($event->dtend, $ui_tz); | ||
| // All day events ends at next day midnight, we should fix the day | ||
| $dtend->modify('-1 day'); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is right. From RFC 5545 (https://tools.ietf.org/html/rfc5545#page-54) From what I understand, |
||
| } else { | ||
| $dtstr .= $rcmail->format_date($dtend, $combined_format); | ||
| // Events with proper time should use calendar timezone. | ||
| // Note that if DTSTART/DTEND ends with "Z", UTC is used instead of the given timezone automatically | ||
| $dtstart = new DateTime($event->dtstart, $ical_tz); | ||
| $dtend = new DateTime($event->dtend, $ical_tz); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should really be checking if the dates have timezone information instead ... correct me if I'm wrong, but I think it is possible that the event date and the
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What you can do probably is check if |
||
| } | ||
|
|
||
| $is_oneday = $dtstart->format($ymd) === $dtend->format($ymd); | ||
|
|
||
| // Concatenate event date string | ||
| if ($is_all_day) { | ||
| // All day events shouldn't display time | ||
| $dtstr = $rcmail->format_date($dtstart, $date_format) | ||
| . (!$is_oneday ? ' – ' . $rcmail->format_date($dtend, $date_format) : ''); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hyphen instead of dash please. |
||
| } else { | ||
| $dtstr = $rcmail->format_date($dtstart, $combined_format) . ' – ' | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
| . ($is_oneday ? $rcmail->format_date($dtend, $time_format) : $rcmail->format_date($dtend, $combined_format)); | ||
| } | ||
| // Put timezone in date string | ||
| $dtstr .= ' (' . $rcmail->format_date($dtstart, 'T') . ')'; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These try-catch blocks are ugly. Can't we use null coalescing instead?