app/models/task.rb in bookyt_projects-0.3.0 vs app/models/task.rb in bookyt_projects-0.3.1

- old
+ new

@@ -10,18 +10,20 @@ validates :from, :presence => true, :unless => :hours_minutes validates :to, :presence => true, :unless => :hours_minutes validates_numericality_of :hours, :only_integer => true, :unless => :from validates_numericality_of :minutes, :only_integer => true, :unless => :from - before_save :calculate_hours, :if => :hours_minutes + before_save :calculate_hours def hours_minutes minutes || hours end def calculate_hours - self.from = DateTime.now - self.to = self.from + hours.to_i.hours + minutes.to_i.minutes + unless hours.empty? or minutes.empty? + self.from = DateTime.now + self.to = self.from + hours.to_i.hours + minutes.to_i.minutes + end end # The duration of the task in minutes def duration minutes = (to.to_f - from.to_f).to_i / 60