You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
492 B
20 lines
492 B
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
|