class Entry < ApplicationRecord belongs_to :user validates :date, :hours, :minutes, presence: true validates :hours, numericality: { only_integer: true, greater_than_or_equal_to: 0 } validates :minutes, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than: 60 } before_save :normalize_time def total_minutes hours * 60 + minutes end private def normalize_time self.hours += minutes / 60 self.minutes = minutes % 60 end end