aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/chouette/timeband.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/chouette/timeband.rb')
-rw-r--r--app/models/chouette/timeband.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/models/chouette/timeband.rb b/app/models/chouette/timeband.rb
new file mode 100644
index 000000000..9844dd1b1
--- /dev/null
+++ b/app/models/chouette/timeband.rb
@@ -0,0 +1,30 @@
+module Chouette
+
+ class TimebandValidator < ActiveModel::Validator
+ def validate(record)
+ if record.end_time <= record.start_time
+ record.errors[:end_time] << I18n.t('activerecord.errors.models.timeband.start_must_be_before_end')
+ end
+ end
+ end
+
+ class Timeband < Chouette::TridentActiveRecord
+ self.primary_key = "id"
+
+ validates :start_time, :end_time, presence: true
+ validates_with TimebandValidator
+
+ default_scope { order(:start_time) }
+
+ def self.object_id_key
+ "Timeband"
+ end
+
+ def fullname
+ fullname = "#{I18n.l(self.start_time, format: :hour)}-#{I18n.l(self.end_time, format: :hour)}"
+ "#{self.name} (#{fullname})" if self.name
+ end
+
+ end
+
+end