aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/calendar/period.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/calendar/period.rb')
-rw-r--r--app/models/calendar/period.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/app/models/calendar/period.rb b/app/models/calendar/period.rb
index 0f1902e59..5078f2db3 100644
--- a/app/models/calendar/period.rb
+++ b/app/models/calendar/period.rb
@@ -5,8 +5,9 @@ class Calendar::Period
attribute :begin, type: Date
attribute :end, type: Date
- validates_presence_of :begin, :end
validate :check_end_greather_than_begin
+ validates_presence_of :begin, :end
+ validate :validate_dates
def check_end_greather_than_begin
if self.begin and self.end and self.begin > self.end
@@ -37,6 +38,19 @@ class Calendar::Period
end
end
+ def validate_dates
+ validate_begin
+ validate_end
+ end
+
+ def validate_begin
+ errors.add(:begin, I18n.t('activerecord.errors.models.calendar.attributes.dates.illegal_date', date: self.begin.to_s)) unless self.begin.legal?
+ end
+
+ def validate_end
+ errors.add(:end, I18n.t('activerecord.errors.models.calendar.attributes.dates.illegal_date', date: self.end.to_s)) unless self.end.legal?
+ end
+
def cover? date
range.cover? date
end