Skip to content

Commit 49b1d3e

Browse files
committed
Add timezone support for events in ApiController to ensure correct DST handling
1 parent 235b398 commit 49b1d3e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

app/controllers/api_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'icalendar'
2+
require 'tzinfo'
23

34
class ApiController < ApplicationController
45
protect_from_forgery with: :null_session
@@ -23,6 +24,13 @@ def uid
2324

2425
def events
2526
cal = Icalendar::Calendar.new
27+
# Hint to clients (including Apple Calendar) that the calendar's canonical timezone is Europe/London
28+
cal.append_custom_property('X-WR-CALNAME', 'Newspeak House Events')
29+
cal.append_custom_property('X-WR-TIMEZONE', 'Europe/London')
30+
31+
# Provide a full VTIMEZONE definition for Europe/London to ensure correct DST handling
32+
london_tz = TZInfo::Timezone.get('Europe/London')
33+
cal.add_timezone(london_tz.ical_timezone(Time.now))
2634

2735
Event.public_and_confirmed.each do |ev|
2836
cal.event do |e|

0 commit comments

Comments
 (0)