Add times to Conference

Add start hour and end hour to conference to be able to make the schedule times changeable
This commit is contained in:
Ana 2016-08-15 12:26:47 +02:00 committed by Ana María Martínez Gómez
parent 7000e63700
commit b80aff3cce
5 changed files with 50 additions and 1 deletions

View file

@ -54,7 +54,9 @@ class Conference < ActiveRecord::Base
validates_presence_of :title,
:short_title,
:start_date,
:end_date
:end_date,
:start_hour,
:end_hour
validates_uniqueness_of :short_title
validates_format_of :short_title, with: /\A[a-zA-Z0-9_-]*\z/
@ -62,6 +64,7 @@ class Conference < ActiveRecord::Base
# This validation is needed since a conference with a start date greater than the end date is not possible
validate :valid_date_range?
validate :valid_times_range?
before_create :generate_guid
before_create :add_color
before_create :create_email_settings
@ -678,6 +681,19 @@ class Conference < ActiveRecord::Base
errors.add(:start_date, 'Start date is greater than End date') if start_date && end_date && start_date > end_date
end
##
# Checks if start hour of the conference is greater or equal than the end hour
# and that both hours are beetween 0 and 24
#
# Reports an error when such a condition is found
def valid_times_range?
if start_hour && end_hour
errors.add(:start_hour, 'is lower than 0') if start_hour < 0
errors.add(:end_hour, 'is lower or equal than start hour') if end_hour <= start_hour
errors.add(:end_hour, 'is greater than 24') if end_hour > 24
end
end
##
# Calculates the weeks from a start and a end week.
#