mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-26 20:54:21 +01:00
Merge branch 'dst' into dev (fix for #77)
This commit is contained in:
commit
f43cd60403
@ -12,6 +12,7 @@
|
|||||||
- Updated puma for compatibility with openSSL > 1.0
|
- Updated puma for compatibility with openSSL > 1.0
|
||||||
- Documented installation on ArchLinux
|
- Documented installation on ArchLinux
|
||||||
- [TODO DEPLOY] `rake db:seed` then `rake fablab:fix:migrate_admins_group`
|
- [TODO DEPLOY] `rake db:seed` then `rake fablab:fix:migrate_admins_group`
|
||||||
|
- [TODO DEPLAY] `rake fablab:fix:recursive_events_over_DST`
|
||||||
|
|
||||||
## v2.5.10 2017 August 16
|
## v2.5.10 2017 August 16
|
||||||
|
|
||||||
|
@ -80,6 +80,19 @@ module ApplicationHelper
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# 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(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
|
||||||
|
|
||||||
|
|
||||||
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(availability.start_at,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(availability.start_at,end_at)
|
||||||
if event_image
|
if event_image
|
||||||
ei = EventImage.new(attachment: event_image.attachment)
|
ei = EventImage.new(attachment: event_image.attachment)
|
||||||
end
|
end
|
||||||
|
@ -57,5 +57,21 @@ namespace :fablab do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
task recursive_events_over_DST: :environment do
|
||||||
|
include ApplicationHelper
|
||||||
|
groups = Event.group(:recurrence_id).count
|
||||||
|
groups.keys.each do |recurrent_event_id|
|
||||||
|
initial_event = Event.find(recurrent_event_id)
|
||||||
|
Event.where(recurrence_id: recurrent_event_id).where.not(id: recurrent_event_id).each do |event|
|
||||||
|
availability = event.availability
|
||||||
|
if initial_event.availability.start_at.hour != availability.start_at.hour
|
||||||
|
availability.start_at = dst_correction(initial_event.availability.start_at, availability.start_at)
|
||||||
|
availability.end_at = dst_correction(initial_event.availability.end_at, availability.end_at)
|
||||||
|
availability.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user