Add validation

This commit is contained in:
2019-11-06 21:05:46 +03:00
parent 81da30fb01
commit 0f01d2ad01
3 changed files with 31 additions and 1 deletions

View File

@ -4,4 +4,7 @@ module Dayoff
class StartedRecordNotFound < Exception
end
class AlreadyStarted < Exception
end
end

View File

@ -35,6 +35,9 @@ module Dayoff
end
def start(time : Time) : Nil
if started_point
raise AlreadyStarted.new
end
@wrecords.each do |wr|
if time <= wr.start || time <= wr.finish!
raise CrossedTimeSpan.new
@ -46,7 +49,7 @@ module Dayoff
end
def finish(time : Time) : Nil
started = @wrecords.find { |x| x.started? }
started = started_point
if started.nil?
raise StartedRecordNotFound.new
end
@ -59,5 +62,9 @@ module Dayoff
worked = get_work_hours on_time
planned - worked
end
private def started_point
@wrecords.find { |x| x.started? }
end
end
end