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

[bug] reccursive events have difference with requested time when crossing DST (#77)

This commit is contained in:
Sylvain 2017-09-04 16:50:07 +02:00
parent 112b174e5f
commit 31cdc5c695
2 changed files with 8 additions and 7 deletions

View File

@ -82,14 +82,15 @@ module ApplicationHelper
##
# Apply a correction for a future DateTime due to change in Daylight Saving Time (DST) period
# @param reference {ActiveSupport::TimeWithZone}
# @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
def dst_correction(reference, datetime)
res = datetime.in_time_zone(reference.time_zone.tzinfo.name)
res = res - 1.hour if res.dst? && !reference.dst?
res = res + 1.hour if reference.dst? && !res.dst?
res
end

View File

@ -88,10 +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)
start_at = dst_correction(availability.start_at,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)
end_at = dst_correction(availability.start_at,end_at)
if event_image
ei = EventImage.new(attachment: event_image.attachment)
end