Skip to content

Commit

Permalink
Update ical to generate the correct times while adjusting for timezon…
Browse files Browse the repository at this point in the history
…e. Add test (#82)
  • Loading branch information
crespire authored Nov 20, 2024
1 parent 2eabe89 commit d5d1de5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
6 changes: 1 addition & 5 deletions app/models/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ def timezone
@timezone ||= TZInfo::Timezone.get(timezone_identifier)
end

def ical_timezone
timezone.ical_timezone(timezone.now)
end

def ical_time(datetime)
Icalendar::Values::DateTime.new(datetime, tzid: timezone_identifier)
Icalendar::Values::DateTime.new(datetime.in_time_zone(timezone_identifier), tzid: timezone_identifier)
end
end
2 changes: 1 addition & 1 deletion test/controllers/events_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class EventsControllerTest < ActionController::TestCase
def setup
Event.destroy_all
begining = Date.parse('2024-01-01').beginning_of_year
dates = 12.times.map { |i| begining + i.months }
dates = 12.times.map { |i| begining.to_datetime.change(hour: 19, zone: 'America/Toronto') + i.months }
@events = dates.map do |date|
Event.create!(
start_at: date,
Expand Down
24 changes: 24 additions & 0 deletions test/models/calendar_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'test_helper'

class CalendarTest < ActiveSupport::TestCase
def setup
@event = Event.create(
'name' => "Toronto Ruby's One Year Anniversary",
'location' => '<div>Some Office</div>',
'rsvp_link' => 'https://test.com',
'description' => '<div>DESCRIPTION</div>',
'sponsor' => '',
'sponsor_link' => '',
'sponsor_logo' => '',
'start_at' => '2024-11-26T00:30Z',
'status' => 'published'
)
@calendar = Calendar.new([@event])
end

test 'ical_time produces the correct time' do
want = DateTime.parse('2024-11-25T19:30-05:00').to_i
got = @calendar.send(:ical_time, @event.start_at)
assert_same(want, got.to_i)
end
end

0 comments on commit d5d1de5

Please sign in to comment.