1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-28 09:24:24 +01:00

[bug] invalid time for reccurent events after Daylight Saving Time change

This commit is contained in:
Sylvain 2017-08-31 17:32:04 +02:00
parent 3d4260a3f7
commit 112b174e5f
2 changed files with 15 additions and 0 deletions

View File

@ -80,6 +80,18 @@ module ApplicationHelper
nil
end
##
# Apply a correction for a future DateTime due to change in Daylight Saving Time (DST) period
# @param datetime {DateTime}
# Inspired by https://stackoverflow.com/a/12065605
##
def dst_correction(datetime)
datetime = datetime.in_time_zone(Time.zone.tzinfo.name)
datetime = datetime - 1.hour if datetime.dst? && !Time.now.dst?
datetime = datetime + 1.hour if Time.now.dst? && !datetime.dst?
datetime
end
private
## inspired by gems/actionview-4.2.5/lib/action_view/helpers/translation_helper.rb

View File

@ -1,5 +1,6 @@
class Event < ActiveRecord::Base
include NotifyWith::NotificationAttachedObject
include ApplicationHelper
has_one :event_image, as: :viewable, dependent: :destroy
accepts_nested_attributes_for :event_image, allow_destroy: true
@ -87,8 +88,10 @@ class Event < ActiveRecord::Base
r.events.each do |date|
days_diff = availability.end_at.day - availability.start_at.day
start_at = DateTime.new(date.year, date.month, date.day, availability.start_at.hour, availability.start_at.min, availability.start_at.sec, availability.start_at.zone)
start_at = dst_correction(start_at)
end_date = date + days_diff.days
end_at = DateTime.new(end_date.year, end_date.month, end_date.day, availability.end_at.hour, availability.end_at.min, availability.end_at.sec, availability.end_at.zone)
end_at = dst_correction(end_at)
if event_image
ei = EventImage.new(attachment: event_image.attachment)
end