mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-17 11:54:22 +01:00
[bug] invalid time for reccurent events after Daylight Saving Time change
This commit is contained in:
parent
3d4260a3f7
commit
112b174e5f
@ -80,6 +80,18 @@ module ApplicationHelper
|
|||||||
nil
|
nil
|
||||||
end
|
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
|
private
|
||||||
## inspired by gems/actionview-4.2.5/lib/action_view/helpers/translation_helper.rb
|
## inspired by gems/actionview-4.2.5/lib/action_view/helpers/translation_helper.rb
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
class Event < ActiveRecord::Base
|
class Event < ActiveRecord::Base
|
||||||
include NotifyWith::NotificationAttachedObject
|
include NotifyWith::NotificationAttachedObject
|
||||||
|
include ApplicationHelper
|
||||||
|
|
||||||
has_one :event_image, as: :viewable, dependent: :destroy
|
has_one :event_image, as: :viewable, dependent: :destroy
|
||||||
accepts_nested_attributes_for :event_image, allow_destroy: true
|
accepts_nested_attributes_for :event_image, allow_destroy: true
|
||||||
@ -87,8 +88,10 @@ class Event < ActiveRecord::Base
|
|||||||
r.events.each do |date|
|
r.events.each do |date|
|
||||||
days_diff = availability.end_at.day - availability.start_at.day
|
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 = 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_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 = 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
|
if event_image
|
||||||
ei = EventImage.new(attachment: event_image.attachment)
|
ei = EventImage.new(attachment: event_image.attachment)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user