Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Enable multiple timezones in the meeting iCal feed

Klaus Zanderscae7fbf8051b
diff --git a/modules/meeting/app/services/meetings/icalendar_builder.rb b/modules/meeting/app/services/meetings/icalendar_builder.rb
index f1dc2c8790b..69409e72b01 100644
--- a/modules/meeting/app/services/meetings/icalendar_builder.rb
+++ b/modules/meeting/app/services/meetings/icalendar_builder.rb
@@ -32,14 +32,13 @@ require "icalendar/tzinfo"
module Meetings
class IcalendarBuilder
- attr_reader :timezone, :calendar, :all_times, :tzid, :calendar_generated_for_user
+ attr_reader :build_timezone, :calendar, :all_times, :calendar_generated_for_user
def initialize(timezone:, user: User.current)
@calendar_generated_for_user = user
- @timezone = timezone
- @tzid = timezone.tzinfo.canonical_identifier
+ @build_timezone = timezone
@calendar = build_icalendar
- @all_times = []
+ @all_times = Hash.new { |hash, key| hash[key] = Array.new }
@excluded_dates_cache = {}
@instantiated_occurrences_cache = {}
@series_cache_loaded = false
@@ -109,7 +108,7 @@ module Meetings
add_attendees(event: e, meeting: recurring_meeting.template)
# Add all occurence dates to the dates set, so that we bake in all timezone rules correcly
- all_times.push(recurring_meeting.schedule.all_occurrences.max)
+ all_times[build_timezone].push(recurring_meeting.schedule.all_occurrences.max)
# Add exceptions for all cancelled recurrences
set_excluded_recurrence_dates(event: e, recurring_meeting: recurring_meeting)
@@ -162,7 +161,7 @@ module Meetings
def to_ical
calendar.timezones.clear
- calendar.add_timezone(build_single_vtimezone)
+ build_timezones
calendar.to_ical
end
@@ -229,9 +228,12 @@ module Meetings
calendar_generated_for_user == user && @action_needed_from_user_as_attendee
end
- def ical_datetime(time)
+ def ical_datetime(time, timezone = build_timezone)
+ tzid = timezone.tzinfo.canonical_identifier
+
time_in_time_zone = time.in_time_zone(timezone)
- all_times << time_in_time_zone
+ all_times[timezone] << time_in_time_zone
+
Icalendar::Values::DateTime.new time_in_time_zone, "tzid" => tzid
end
@@ -241,27 +243,28 @@ module Meetings
sprintf("%<hours>+03d%<minutes>02d", hours:, minutes:)
end
- # Helper to build a VTZIMEZONE with all relevant transitions
- def build_single_vtimezone # rubocop:disable Metrics/AbcSize
- tz = Icalendar::Timezone.new
- tz.tzid = tzid
-
- # We are investigating how to properly build this ... for now let's
- # just include everything from min - 6 months to max + 6 months
- if all_times.present?
- transitions = timezone.tzinfo.transitions_up_to(all_times.max + 6.months, all_times.min - 6.months)
-
- transitions.each do |tr|
- comp = tr.offset.dst? ? Icalendar::Timezone::Daylight.new : Icalendar::Timezone::Standard.new
- comp.dtstart = tr.at.utc.strftime("%Y%m%dT%H%M%SZ")
- comp.tzoffsetfrom = format_ical_offset(tr.previous_offset.utc_total_offset)
- comp.tzoffsetto = format_ical_offset(tr.offset.utc_total_offset)
- comp.tzname = tr.offset.abbreviation.to_s
- tz.add_component(comp)
+ def build_timezones # rubocop:disable Metrics/AbcSize
+ all_times.each do |timezone, times|
+ calendar.timezone do |tz|
+ tz.tzid = timezone.tzinfo.canonical_identifier
+ transitions = timezone.tzinfo.transitions_up_to(times.max + 6.months, times.min - 6.months)
+
+ transitions.each do |tr|
+ if tr.offset.dst?
+ tz.daylight { |d| transition_to_component(d, tr) }
+ else
+ tz.standard { |s| transition_to_component(s, tr) }
+ end
+ end
end
end
+ end
- tz
+ def transition_to_component(component, transition)
+ component.dtstart = transition.at.utc.strftime("%Y%m%dT%H%M%SZ")
+ component.tzoffsetfrom = format_ical_offset(transition.previous_offset.utc_total_offset)
+ component.tzoffsetto = format_ical_offset(transition.offset.utc_total_offset)
+ component.tzname = transition.offset.abbreviation.to_s
end
def ical_organizer