Skip to content

Commit 6de02f0

Browse files
committed
Fixed Ration Club timezone issue
1 parent ecf3713 commit 6de02f0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

app/controllers/api_controller.rb

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

45
class ApiController < ApplicationController
@@ -45,10 +46,12 @@ def events
4546
end
4647

4748
# Add weekly Ration Club (Wednesdays, 7–10pm London time)
48-
now_london = Time.now.in_time_zone('Europe/London')
49-
days_until_wed = (3 - now_london.wday) % 7
50-
ration_start = (now_london.to_date + days_until_wed).to_time.in_time_zone('Europe/London') + 19.hours
51-
ration_end = ration_start + 3.hours
49+
now_london = Time.zone.now.in_time_zone('Europe/London')
50+
days_until_wed = (3 - now_london.wday) % 7
51+
wednesday = (now_london + days_until_wed.days)
52+
53+
ration_start = wednesday.change(hour: 19, min: 0, sec: 0)
54+
ration_end = ration_start + 3.hours
5255

5356
cal.event do |e|
5457
e.dtstart = Icalendar::Values::DateTime.new(ration_start, tzid: 'Europe/London')

0 commit comments

Comments
 (0)